显示一个交互式的Bokeh图表。
Bokeh 是一个用于 Python 的图表库。此函数的参数与 Bokeh 的 show 函数的参数非常相似。你可以在 https://bokeh.pydata.org 上找到更多关于 Bokeh 的信息。
要在Streamlit中显示Bokeh图表,可以在调用Bokeh的show的地方调用st.bokeh_chart。
重要
你必须安装 bokeh==2.4.3 和 numpy<2 才能使用此命令。
| 函数签名[source] | |
|---|---|
st.bokeh_chart(图表, use_container_width=False) | |
| 参数 | |
figure (bokeh.plotting.figure.Figure) | 用于绘图的Bokeh图形。 |
use_container_width (bool) | 是否用父容器的宽度覆盖图形的原生宽度。如果use_container_width是False (默认),Streamlit会根据绘图库设置图表的宽度以适应其内容,直到父容器的宽度。如果use_container_width是True,Streamlit会将图形的宽度设置为与父容器的宽度匹配。 |
示例
import streamlit as st from bokeh.plotting import figure x = [1, 2, 3, 4, 5] y = [6, 7, 2, 4, 5] p = figure(title="simple line example", x_axis_label="x", y_axis_label="y") p.line(x, y, legend_label="Trend", line_width=2) st.bokeh_chart(p, use_container_width=True)
还有问题吗?
我们的 论坛 充满了有用的信息和Streamlit专家。