顯示交互式 Plotly 圖表。
Plotly 是 Python 的圖表庫。該函數的參數緊跟 Plotly 的 plot()
函數的參數。您可以在 https://plot.ly/python 找到更多關於 Plotly 的信息。
要在 Streamlit 中顯示 Plotly 圖表,請在調用 Plotly 的 py.plot
或 py.iplot
的任何地方調用 st.plotly_chart
。
函數簽名
st.plotly_chart(figure_or_data, use_container_width=False, sharing="streamlit", **kwargs)
參數 | 說明 |
---|---|
figure_or_data (plotly.graph_objs.Figure, plotly.graph_objs.Data,) | dict/list of plotly.graph_objs.Figure/Data 有關圖形說明的示例,請參見https://plot.ly/python/。 |
use_container_width (bool) | 如果為 True,則將圖表寬度設置為列寬。這優先於圖窗的原生 |
sharing ({'streamlit', 'private', 'secret', 'public'}) | 使用 'streamlit' 使用 plotly 的離線模式(默認)直接在 Streamlit 應用程序中插入繪圖及其所有依賴項。使用任何其他共享模式將圖表發送到需要帳戶的 Plotly 圖表工作室。有關詳細信息,請參閱https://plotly.com/chart-studio/。 |
**kwargs (null) | Plotly 的 |
示例
下麵的示例直接來自 https://plot.ly/python 的示例:
import streamlit as st
import plotly.figure_factory as ff
import numpy as np
# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
# Group data together
hist_data = [x1, x2, x3]
group_labels = ['Group 1', 'Group 2', 'Group 3']
# Create distplot with custom bin_size
fig = ff.create_distplot(
hist_data, group_labels, bin_size=[.1, .25, .5])
# Plot!
st.plotly_chart(fig, use_container_width=True)
相關用法
- Python Streamlit st.pydeck_chart用法及代碼示例
- Python Streamlit st.progress用法及代碼示例
- Python Streamlit st.pyplot用法及代碼示例
- 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.plotly_chart。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。