isabel-beard
12/13/2018 - 2:34 PM

Bokeh snippets

Collection of useful bokeh snippets

from bokeh.models import ColumnDataSource
source = ColumnDataSource(nicknamesGender)

#Show in notebook
from bokeh.io import output_notebook
output_notebook()

#Set up figure
p = figure(plot_height = 500, plot_width = 700, title = 'Title')

#Remove logo and toolbar
p.toolbar.logo = None
p.toolbar_location = None

#Add hover states
from bokeh.models.tools import HoverTool
hover = HoverTool()
hover.tooltips = [
    ('Var', '@Var'),
]
p.add_tools(hover)

#Mapping color (before ColumnDataSource())
colormap = {'Yes': '#333745', 'No': '#B4BFD6'}
df['color'] = [df[x] for x in df['Cat']]

#Show plot
show(p)