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

初学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

posted @   ohfaint  阅读(67)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示