st.pyplot(fig=None, clear_figure=None, **kwargs)
fig (Matplotlib Figure)
The figure to plot. When this argument isn't specified, this function will render the global figure (but this is deprecated, as described below)
If True, the figure will be cleared after being rendered. If False, the figure will not be cleared after being rendered. If left unspecified, we pick a default based on the value of fig.
Arguments to pass to Matplotlib's savefig function.
import matplotlib.pyplot as plt import numpy as np arr = np.random.normal(1, 1, size=100) fig, ax = plt.subplots() ax.hist(arr, bins=20) st.pyplot(fig)(view standalone Streamlit app)
Deprecation warning. After December 1st, 2020, we will remove the ability to specify no arguments in st.pyplot(), as that requires the use of Matplotlib's global figure object, which is not thread-safe. So please always pass a figure object as shown in the example section above.
Matplotlib support several different types of "backends". If you're getting an error using Matplotlib with Streamlit, try setting your backend to "TkAgg":echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
For more information, see https://matplotlib.org/faq/usage_faq.html.