bokeh.themes#
提供对内置主题的访问:
内置主题#
口径#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'caliber'
p = figure(title='caliber', width=300, height=300)
p.line(x, y)
show(p)
碳#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'carbon'
p = figure(title='carbon', width=300, height=300)
p.line(x, y)
show(p)
DARK_MINIMAL#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'dark_minimal'
p = figure(title='dark_minimal', width=300, height=300)
p.line(x, y)
show(p)
LIGHT_MINIMAL#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'light_minimal'
p = figure(title='light_minimal', width=300, height=300)
p.line(x, y)
show(p)
夜空#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'night_sky'
p = figure(title='night_sky', width=300, height=300)
p.line(x, y)
show(p)
对比#
from bokeh.plotting import curdoc, figure, show
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
curdoc().theme = 'contrast'
p = figure(title='contrast', width=300, height=300)
p.line(x, y)
show(p)
主题#
- class Theme(filename: str | PathLike[str])[source]#
- class Theme(json: dict[str, Any])
为Bokeh模型提供新的默认值。
Bokeh 模型属性都有一些内置的默认值。如果某个属性没有显式设置(例如
m.foo = 10),访问该属性将返回默认值。对于用户来说,能够指定一组不同于内置默认值的默认值可能很有用。Theme类允许将自定义默认值的集合轻松应用于 Bokeh 文档。Theme类可以从 YAML 文件或 JSON 字典(但不能同时使用两者)构建。下面展示了两种格式的示例。绘图API默认值会覆盖一些主题属性。即: fill_alpha, fill_color, line_alpha, line_color, text_alpha 和 text_color。因此,在使用绘图API时,应明确设置这些属性。
- Parameters:
- Raises:
ValueError – 如果既没有提供
filename也没有提供json。
示例
主题通过提供一个顶级键
attrs来指定,该键包含要为模型类型设置主题的块。每个块都有键和值,用于指定该类型的新属性默认值。请注意,YAML将值None解释为字符串,这通常不是您想要的。要在YAML中给出None作为值,请使用!!null。要在json中给出‘None’作为值,请使用null。
以下是一个YAML格式的主题示例,它为所有图形、网格和标题设置了各种视觉属性:
attrs: Plot: 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"
这是相同的主题,以JSON格式呈现:
{ 'attrs' : { 'Plot': { 'background_fill_color': '#2F2F2F', 'border_fill_color': '#2F2F2F', 'outline_line_color': '#444444', }, 'Axis': { 'axis_line_color': None, }, 'Grid': { 'grid_line_dash': [6, 4], 'grid_line_alpha': .3, }, 'Title': { 'text_color': 'white' } } }