初学Bokeh:调整绘图大小【15】跬步

发布时间 2023-10-18 21:23:52作者: ohfaint

初学Bokeh:调整绘图大小【15】跬步

Bokeh 中的绘图对象具有多种属性,这些属性会影响绘图的外观。

调用 figure() 函数时使用 width 和 height 属性就可以设置绘图的大小:

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 a specific size
# 创建一个绘图对象
p = figure(
    title="Plot sizing example",    # 标题
    width=350,  # 宽度
    height=250, # 高度
    x_axis_label="x",   # x轴标签
    y_axis_label="y",   # y轴标签
)

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

# show the results
show(p)

fig15-1

与更改现有字体的方法类似,也可以在创建绘图后随时更改绘图的大小:

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 a specific size
# 创建一个绘图对象
p = figure(
    title="Plot resizing example",  # 标题
    width=350,  # 宽度
    height=250, # 高度
    x_axis_label="x",   # x轴标签
    y_axis_label="y",   # y轴标签
)

# change plot size
# 更改绘图尺寸
p.width = 450   # 宽度
p.height = 150  # 高度

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

# show the results
show(p)

fig15-2