HoverTool for multiple data series in bokeh scatter plot

The original answer was ancient and outdated, here is how to accomplish this with any modern version of Bokeh:

from bokeh.plotting import figure, show
import numpy as np

x = np.linspace(0, 2*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)

fig = figure(tools="reset", tooltips=[("x", "$x"), ("y", "$y")])
s1 = fig.scatter(x, y1, color='#0000ff', size=10, legend_label='sine')
s2 = fig.scatter(x, y2, color='#ff0000', size=10, legend_label='cosine')

show(fig)

Edit: Note that the approach below is necessary only if you want different tooltips for different glyphs. If you want the same tooltips for all glyphs, see the answer above.


If you want to have multiple hover tools, you need to add multiple hover tools, each configured for a different renderer. You can add them this way:

p = figure()

r1 = p.circle([1,2,3], [4,5,6], color="blue")
p.add_tools(HoverTool(renderers=[r1], tooltips=TIPS))

r2 = p.square([4,5,6], [1,2,3], color="red")
p.add_tools(HoverTool(renderers=[r2], tooltips=TIPS))

Tags:

Python

Bokeh