主题#
使用主题#
Bokeh的主题是一组预定义的设计参数,您可以将其应用于您的图表。主题可以包括颜色、字体或线条样式等参数的设置。
应用Bokeh的内置主题#
Bokeh 提供了五种内置主题,可以快速更改一个或多个图表的外观:caliber、dark_minimal、light_minimal、night_sky 和 contrast。
要使用内置主题之一,请将您想要使用的主题名称分配给文档的theme属性。
例如:
from bokeh.io import curdoc
from bokeh.plotting import figure, output_file, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
output_file("dark_minimal.html")
curdoc().theme = 'dark_minimal'
p = figure(title='dark_minimal', width=300, height=300)
p.line(x, y)
show(p)
更多示例和详细信息,请参见bokeh.themes。
创建自定义主题#
Bokeh中的主题是在YAML或JSON文件中定义的。要创建自己的主题文件,请遵循bokeh.themes.Theme中定义的格式。
使用YAML,例如:
attrs:
figure:
background_fill_color: '#2F2F2F'
border_fill_color: '#2F2F2F'
outline_line_color: '#444444'
Axis:
axis_line_color: !!null
Grid:
grid_line_dash: [6, 4]
grid_line_alpha: .3
Title:
text_color: "white"
要在Bokeh图中使用您的自定义主题,请将您的YAML或JSON文件加载到bokeh.themes.Theme对象中:
from bokeh.themes import Theme
curdoc().theme = Theme(filename="./theme.yml")