How to set default style in bokeh?

I am writing a report whose stories are displayed using Matplotlib. I set Matplotlibdefault so that all graphs have the same style.

However, I need to use Bokehit as it provides support for creating legends for Datashader- a library developed by people at Bokeh.

My problem is that the Bokehdefault style is very different from my custom style. Instead of changing every single attribute on my chart Bokeh, one could Bokehread the stylesheet just like Matplotlibwith plt.use.style(['ggplot'])?

+4
source share
1 answer

As with Bokeh 0.12.4, there are still open issues in Bokeh (features for development, as well as a few bugs and additional documentation support). What is currently supported is based on a type using an object Themethat can be set in the current document.

The object Themeaccepts a JSON block, general view:

 { 
   'attrs: {
       'SomeTypeName': { 'foo_property': default_foo },
       'OtherTypeName': { 'bar_property': default_bar }
   }
 }

Or for a specific 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 can also be read from a file using standard Python JSON tools.

If this also happens in the context of the Bokeh server application (directory style), you can also specify the theme as a file theme.yamlin the same directory as yours main.py. See, for example, Example Gapminder .

+2
source

Source: https://habr.com/ru/post/1668556/


All Articles