In [1]:
from bokeh.sampledata.glucose import data
(x, y) = (data.ix['2010-10-06'].index.to_series(), data.ix['2010-10-06']['glucose'])
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import ColumnDataSource, Circle, HoverTool, Callback
output_notebook()
In [2]:
# Basic plot setup
p = figure(
width=750,
height=300,
x_axis_type="datetime",
outline_line_color=None,
tools="",
toolbar_location=None,
title='Hover over points on line'
)
p.line(x, y, line_dash="4 4", line_width=1, color='gray')
p.xaxis[0].axis_line_color = None
p.yaxis[0].axis_line_color = None
p.xgrid[0].grid_line_color = None
p.ygrid[0].grid_line_alpha =0.5
p.xaxis[0].major_label_text_color = 'gray'
p.xaxis[0].major_tick_line_color = 'gray'
p.yaxis[0].major_label_text_color = 'gray'
p.yaxis[0].minor_tick_line_color = None
p.yaxis[0].major_tick_line_color = None
# Add a circle, that is visible only when selected
source = ColumnDataSource({'x': x, 'y': y})
size = 20
invisible_circle = Circle(x='x', y='y', fill_color='gray', fill_alpha=0.05, line_color=None, size=size)
visible_circle = Circle(x='x', y='y', fill_color='firebrick', fill_alpha=0.5, line_color=None, size=size)
circle = p.add_glyph(source, invisible_circle, selection_glyph=visible_circle, nonselection_glyph=invisible_circle)
# Add a hover tool, that selects the circle
code = "source.set('selected', cb_data['index']);"
callback = Callback(args={'source': source}, code=code)
p.add_tools(HoverTool(tooltips=None, callback=callback, renderers=[circle], mode='hline'))
show(p)