How to add hover tooltip for a plot which contains multiple data sources?

Hi,
I am new to Bokeh. The doc shows I should do something like this to create a tooltip.

source = ColumnDataSource(data=dict(
 x=[1, 2, 3, 4, 5],
 y=[2, 5, 8, 2, 7],
 desc=['A', 'b', 'C', 'd', 'E'],
))

hover = HoverTool(tooltips=[
 ("index", "$index"),
 ("(x,y)", "(@x, @y)"),
 ("desc", "@desc"),
])

so if the plot is using multiple data sources, it seems I am not able to use @xxx to specify a column.

and if i am not using a ColumnDataSource, how to make the mapping work? e.g. to add tooltip for https://bokeh.pydata.org/en/latest/docs/gallery/candlestick.html

Hi,

If you are using cover tools, my recommendation is to always make your own ColumnDataSources, so that you know and control exactly what the column names are. Bokeh will *always* use a CDS, but if you don't provide one yourself (like the example below) then Bokeh makes one, with some default column names depending on the glyph fields (e.g. "x", "radius", etc).

If the data are all the same length, it's possible to drive multiple glyphs for a single CDS, in which case you can just make a single hover tool with whatever columns you want, from that one CDS. That's another good reason to create your own CDS explicitly.

If the glyphs have different data lengths then you will have to make separate CDS for them. All columns in a given CDS must alway be the *same length* at all times (think of them like cheap Pandas DataFrames). In this case you will need to make multiple hover tools. By default hover tools try to hover for every glyph, but you can restrict different hover tools to different glyphs by using the .renderers property on the tool.

Thanks,

Bryan

ยทยทยท

On Dec 5, 2017, at 03:02, [email protected] wrote:

Hi,
I am new to Bokeh. The doc shows I should do something like this to create a tooltip.

source = ColumnDataSource(data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
desc=['A', 'b', 'C', 'd', 'E'],
))

hover = HoverTool(tooltips=[
("index", "$index"),
("(x,y)", "(@x, @y)"),
("desc", "@desc"),
])

so if the plot is using multiple data sources, it seems I am not able to use @xxx to specify a column.

and if i am not using a ColumnDataSource, how to make the mapping work? e.g. to add tooltip for https://bokeh.pydata.org/en/latest/docs/gallery/candlestick.html

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/3ba5d60f-cfa1-4b16-9049-271a2049adde%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.