Bokeh: Hover Tool with overlaid plots

Created on 17 Mar 2015  路  3Comments  路  Source: bokeh/bokeh

If I plot multiple glyph sets on the same figure, is there a way to attach a hovertool to only a subset of them?

completed discussion

Most helpful comment

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)

All 3 comments

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")]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jnettels picture jnettels  路  3Comments

bald picture bald  路  4Comments

tommycarstensen picture tommycarstensen  路  4Comments

sggaffney picture sggaffney  路  3Comments

abdelwahed picture abdelwahed  路  4Comments