I'm writing a report whose plots are all rendered with Matplotlib
. I've adjusted Matplotlib
's default to ensure that all plots have the same style.
However, I need to use Bokeh
since it provides support for rendering legends for Datashader
- a library being developed by the folks at Bokeh
.
My issue is that the default Bokeh
style is very different from my custom style. Rather than changing every single attribute in my Bokeh
plot would it be possible to have Bokeh
read from a style sheet in a similar way as Matplotlib
does with plt.use.style(['ggplot'])
?
As of Bokeh 0.12.4
there are still open issues (features to develop as well as a few bugs, and more documentation support) around theming in Bokeh. What is currently supported is type-based theming using a Theme
object that can be set on the current document.
The Theme
object takes a JSON block, of the general form:
{
'attrs: {
'SomeTypeName': { 'foo_property': default_foo },
'OtherTypeName': { 'bar_property': default_bar }
}
}
Or for a concrete example:
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,
}
}})
This JSON could also be read from a file using standard Python JSON tools.
If this also happens to be in the context of a (directory style) Bokeh server application, you can also provide the theme as a theme.yaml
file in the same directory as your main.py
. See, e.g., the Gapminder example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With