Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh Plotting: Enable tooltips for only some glyphs

I have a figure with some glyphs, but only want tooltips to display for certain glyphs. Is there currently a way to accomplish this in Bokeh?

Alternatively, is there a way to plot two figures on top of each other? It seems like that would let me accomplish what I want to do.

like image 905
Imaduck Avatar asked Apr 03 '15 15:04

Imaduck


1 Answers

Thanks to this page in Google Groups I figured out how this can be done. Link here

Edit 2015-10-20: looks like the google group link doesn't work anymore unfortunately. It was a message from Sarah Bird @bokehplot.

Edit 2017-01-18: Currently this would add multiple hover tool icons to the tool bar. This may cause problems. There is already an issue filed at github here. Alternatively, try @tterry's solution in the answer below.

Essentially you need to (bokeh version 0.9.2):

  1. not add hover in your tools when you create the figure
  2. create glyphs individually
  3. add glyphs to your figure
  4. set up the hover tool for this set of glyphs
  5. add the hover tool to your figure

Example:

import bokeh.models as bkm import bokeh.plotting as bkp  source = bkm.ColumnDataSource(data=your_frame) p = bkp.figure(tools='add the tools you want here, but no hover!') g1 = bkm.Cross(x='col1', y='col2') g1_r = p.add_glyph(source_or_glyph=source, glyph=g1) g1_hover = bkm.HoverTool(renderers=[g1_r],                          tooltips=[('x', '@col1'), ('y', '@col2')]) p.add_tools(g1_hover)  # now repeat the above for the next sets of glyphs you want to add.  # for those you don't want tooltips to show when hovering over, just don't  # add hover tool for them! 

Also if you need to add legend to each of the glyphs you are adding, try using bokeh.plotting_helpers._update_legend() method. github source Eg:

_update_legend(plot=p, legend_name='data1', glyph_renderer=g1_r) 
like image 184
WillZ Avatar answered Sep 16 '22 12:09

WillZ