初学Bokeh:使用自适应绘图大小【16】跬步

发布时间 2023-10-19 09:36:35作者: ohfaint

学习Bokeh:使用自适应绘图大小【16】跬步

在绘图的过程中,如果要使绘图自动适应浏览器或屏幕大小,可以使用属性:sizing_mode

from bokeh.plotting import figure, show

# prepare some data
# 定义显示数据
x = [1, 2, 3, 4, 5]
y = [4, 5, 5, 7, 2]

# create a new plot with responsive width
# 创建一个绘图对象
p = figure(
    title="Plot responsive sizing example", # 标题
    sizing_mode="stretch_width",   # 宽度自动拉伸 
    height=250, # 高度
    x_axis_label="x",   # x轴标识
    y_axis_label="y",   # y轴标识
)

# add circle renderer
# 添加一个圆对象
circle = p.circle(x, y, fill_color="red", size=15)

# show the results
show(p)

fig16-1