提供对内置主题的访问:
from bokeh.plotting import figure, output_file, show from bokeh.themes import built_in_themes from bokeh.io import curdoc x = [1, 2, 3, 4, 5] y = [6, 7, 6, 4, 5] output_file("caliber.html") curdoc().theme = 'caliber' p = figure(title='caliber', plot_width=300, plot_height=300) p.line(x, y) show(p)
from bokeh.plotting import figure, output_file, show from bokeh.themes import built_in_themes from bokeh.io import curdoc 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', plot_width=300, plot_height=300) p.line(x, y) show(p)
from bokeh.plotting import figure, output_file, show from bokeh.themes import built_in_themes from bokeh.io import curdoc x = [1, 2, 3, 4, 5] y = [6, 7, 6, 4, 5] output_file("light_minimal.html") curdoc().theme = 'light_minimal' p = figure(title='light_minimal', plot_width=300, plot_height=300) p.line(x, y) show(p)
from bokeh.plotting import figure, output_file, show from bokeh.themes import built_in_themes from bokeh.io import curdoc x = [1, 2, 3, 4, 5] y = [6, 7, 6, 4, 5] output_file("night_sky.html") curdoc().theme = 'night_sky' p = figure(title='night_sky', plot_width=300, plot_height=300) p.line(x, y) show(p)
from bokeh.plotting import figure, output_file, show from bokeh.themes import built_in_themes from bokeh.io import curdoc x = [1, 2, 3, 4, 5] y = [6, 7, 6, 4, 5] output_file("contrast.html") curdoc().theme = 'contrast' p = figure(title='contrast', plot_width=300, plot_height=300) p.line(x, y) show(p)
以及 Theme 类,该类可用于创建新主题。
Theme
为Bokeh模型提供新的默认值。
Bokeh模型属性都有一些内置的默认值。如果属性没有被显式设置(例如。 m.foo = 10 )然后访问属性并返回默认值。用户可以指定一组不同于内置默认值的默认值,这可能会很有用。这个 Theme 类允许将自定义默认值的集合轻松应用于Bokeh文档。
m.foo = 10
这个 Theme 类可以从YAML文件或JSON dict(但不能同时从两者)构造。两种格式的示例如下所示。
绘图API的默认设置会覆盖某些主题属性。即: fill_alpha , fill_color , line_alpha , line_color , text_alpha 和 text_color . 因此,在使用绘图API时,应该显式地设置这些属性。
filename (str, optional) -- YAML主题文件的路径
json (str, optional) -- 指定主题值的JSON字典
ValueError -- 如果既不 filename 或 json 供应。
filename
json
实际案例
主题是通过提供顶级键来指定的 attrs 其中包含要设置主题的模型类型的块。每个块都有指定该类型的新特性默认值的键和值。
attrs
注意YAML解释值的事实 None 作为一个字符串,这通常不是你想要的。给予 None 作为YAML中的值,使用 !!null . 在json中使用' null .
下面是一个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" 以下是JSON格式的相同主题: { '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' } }
下面是一个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" 以下是JSON格式的相同主题: { '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' } }
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"
以下是JSON格式的相同主题:
{ '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' } }