Pyplot size problem

Hi,

I’m a new streamlit user, i’m making my first dashboard and I have a problem with the size of one of my plots

This is the code

fig = plt.plot(dfpatient2[‘Datetime’], dfpatient2[select])
plt.gcf().autofmt_xdate()
st.pyplot()

And this is a screenshot of my problem (the plot is too big…)

Thanks

Hi @Nabs33, welcome to the Streamlit community!! :wave: :partying_face:

As you would with any matplotlib figure, you can customize the size of the figure by specifying the width and height (in inches) to the figsize parameter of plt.figure(). E.g. fig = plt.figure(figsize=(7,3)).

Here’s example showing how to set a custom figsize when plotting from a dataframe ts:

import streamlit as st
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# set figsize globally with plt.rcParams["figure.figsize"] = (7, 3)

ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()

fig = plt.figure(figsize=(7,3)) # try different values
ax = plt.axes()

ax.plot(ts) # replace with ax.plot(dfpatient2[‘Datetime’], dfpatient2[select])
plt.gcf().autofmt_xdate()
st.pyplot(fig)

You can experiment with different values in figsize to see what works best for your use case. Let us know if this helps!

Happy Streamlit-ing! :balloon:
Snehan