顯示 matplotlib.pyplot 圖。
函數簽名
st.pyplot(fig=None, clear_figure=None, **kwargs)
參數 | 說明 |
---|---|
fig (Matplotlib Figure) | 要繪製的圖形。當未指定此參數時,此函數將呈現全局圖形(但不推薦使用,如下所述) |
clear_figure (bool) | 如果為 True,則圖形在渲染後將被清除。如果為 False,則圖形在渲染後不會被清除。如果未指定,我們將根據
|
**kwargs (any) | 傳遞給 Matplotlib 的 savefig 函數的參數。 |
示例
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)
注意
注意
棄用警告。 2020 年 12 月 1 日之後,我們將刪除在 st.pyplot()
中不指定參數的函數,因為這需要使用 Matplotlib 的非線程安全的全局圖形對象。因此,請始終傳遞一個圖形對象,如上麵的示例部分所示。
Matplotlib 支持幾種不同類型的"backends"。如果您在使用帶有 Streamlit 的 Matplotlib 時遇到錯誤,請嘗試將後端設置為 "TkAgg":
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
有關詳細信息,請參閱https://matplotlib.org/faq/usage_faq.html。
相關用法
- Python Streamlit st.pydeck_chart用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.progress用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.experimental_singleton用法及代碼示例
- Python Streamlit st.empty用法及代碼示例
- Python Streamlit st.error用法及代碼示例
- Python Streamlit st.video用法及代碼示例
- Python Streamlit st.vega_lite_chart用法及代碼示例
- Python Streamlit st.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.code用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
- Python Streamlit st.image用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.pyplot。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。