How to set the default style in Bokeh?

浪子不回头ぞ 提交于 2019-12-01 19:04:57

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!