初学Bokeh:使用主题【14】跬步

发布时间 2023-10-18 21:08:27作者: ohfaint

初学Bokeh:使用主题【14】跬步

主题是一组预定义的参数打包集合,如颜色、字体或线条样式。使用 Bokeh 的主题,可以快速、方便地更改绘图的外观要素。

Bokeh 包含五种内置主题:caliber、dark_minimal、light_minimal、night_sky 和 contrast。此外,还可以定义自定义主题。

要使用一个内置主题,只要简单的在文档的主题属性中指定主题名称。

from bokeh.io import curdoc
from bokeh.plotting import figure, show

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

# apply theme to current document
# 应用内置主题"dark_minimal"
curdoc().theme = "dark_minimal"

# create a plot
# 创建一个显示对象
p = figure(sizing_mode="stretch_width", max_width=500, height=250)

# add a renderer
# 添加一条折线
p.line(x, y)

# show the results
show(p)

还可以创建自己的主题,以便在多个图集中使用。Bokeh 的主题是 YAML 或 JSON 格式。

fig1