我正在写一份报告,所有图都用Matplotlib
渲染。我已经调整了Matplotlib
的默认值,以确保所有绘图都具有相同的样式。
但是,我需要使用Bokeh
,因为它为Datashader
的呈现图例提供了支持-Bokeh
的人们正在开发一个库。
我的问题是默认的Bokeh
样式与我的自定义样式有很大不同。除了改变Bokeh
图中的每个属性之外,还可以像使用Bokeh
和Matplotlib
一样从样式表中读取plt.use.style(['ggplot'])
吗?
最佳答案
自Bokeh 0.12.4
以来,在Bokeh中的主题化方面仍然存在一些 Unresolved 问题(要开发的功能以及一些错误,以及更多的文档支持)。当前支持的是使用可以在当前文档上设置的Theme
对象的基于类型的主题。Theme
对象采用通用形式的JSON块:
{
'attrs: {
'SomeTypeName': { 'foo_property': default_foo },
'OtherTypeName': { 'bar_property': default_bar }
}
}
或举一个具体的例子:
from bokeh.io import curdoc
from bokeh.themes import Theme
curdoc().theme = Theme(json={'attrs': {
# apply defaults to Figure properties
'Figure': {
'toolbar_location': None,
'outline_line_color': None,
'min_border_right': 10,
},
# apply defaults to Axis properties
'Axis': {
'major_tick_in': None,
'minor_tick_out': None,
'minor_tick_in': None,
'axis_line_color': '#CAC6B6',
'major_tick_line_color': '#CAC6B6',
},
# apply defaults to Legend properties
'Legend': {
'background_fill_alpha': 0.8,
}
}})
也可以使用标准Python JSON工具从文件中读取此JSON。
如果这也恰好是在(目录样式)Bokeh服务器应用程序的上下文中,则还可以将主题作为
theme.yaml
文件提供在与main.py
相同的目录中。参见例如Gapminder example。关于python - 如何在Bokeh中设置默认样式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41987539/