If I plot multiple glyph sets on the same figure, is there a way to attach a hovertool to only a subset of them?
Yes!
I was actually just learning the preferred way to do this. It would be something like this.
edit:
pasted the code in below as its not coming through nicely from email.
This is an adaptation of the code here:
https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables.py
Based on some notes from Bryan here:
https://github.com/bokeh/bokeh/issues/2069
cty = plot.add_glyph(source, cty_glyph)
hwy = plot.add_glyph(source, hwy_glyph)
tooltips = [
("Manufacturer", "@manufacturer"),
("Model", "@model"),
]
cty_hover_tool = HoverTool(renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")])
plot.add_tool(cty_hover_tool)
hwy_hover_tool = HoverTool(renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")])
plot.add_tool(hwy_hover_tool)
Thanks Sarah!! I've got it working now, thanks to your help. One kink is that instead of creating a plot object and adding glyphs, I'm making a figure object and then plotting using its methods. For those following along at home, I've had some luck using, e.g.:
fig = bk.figure(tools="hover,hover")
hover = fig.select(dict(type=HoverTool))
hover[0].renderers = [cty] # overrides the default of using all renderers on the plot
hover[0].tooltips = tooltips + [("City MPG", "@cty")]
hover[1].renderers = [hwy]
hover[1].tooltips = tooltips + [("Highway MPG", "@hwy")]
Most helpful comment