HoverTool tooltips

Hi,

I have a graph that has a number of lines and each line has been given a name.

When I hover over a line, is it possible to access the name of the line in the tooltip, without hardcoding it into the tooltip?

For example:

import sys

import os

import bokeh

import pandas as pd

from collections import OrderedDict

bokeh.io.output_notebook()

x = [0,1,2,3,4]

y1 = [0, 3.5, 8, 4, 5]

y2 = [100, 110, 200, 90, 30.5]

df = pd.DataFrame(data={‘x’:x, ‘y1’:y1, ‘y2’:y2})

f = bokeh.plotting.figure(plot_width=900, plot_height=400)

ds = bokeh.models.ColumnDataSource(df)

line1 = f.line(‘x’, ‘y1’, source=ds, name=‘line1’, color=‘blue’)

line2 = f.line(‘x’, ‘y2’, source=ds, name=‘line2’, color=‘red’)

htool = bokeh.models.HoverTool(mode=‘mouse’, line_policy=‘interp’, tooltips=OrderedDict([(‘x’, ‘@x’), (‘Mouse y’, ‘y'), ('Value:', '~y’), (‘Line Name:’, ‘@NAME’)]))

f.add_tools(htool)

bokeh.io.show(f)

``

Is there some parameter that can be added to the tooltip to display ‘line1’ or ‘line2’ when the user mouses over one of the lines?

Also, I have seen code snippets where people use $~y in the tooltip (the tilde). I cannot see documentation about that anywhere. It seems to display the actual value of the line or marker, but am I correct in saying that?

Thanks,

Adrian.

Hi,

Right now, to have a single hover tool, I think you'd have to add two column to the data sources that names the line each point is in. This is wasteful, but if the data is not big then perhaps it's OK. It might be worth adding an issue on GH to see how this could be improved.

The other approach is to have separate hover tools configured for each line, that each hard code the name of the line in the hover template or tooltips.

The hover "special variables" do need to be documented better. There's only a few partial demonstrations at the moment, as far as I know. Would you mind making a GH issue to request this? Regarding your specific question, I'm not aware of any use of them with a tilde, they are are $x, $sy, i, etc \(just the ), but it's not entirely possible I missed some addition.

Thanks,

Bryan

···

On Mar 21, 2017, at 08:00, [email protected] wrote:

Hi,

I have a graph that has a number of lines and each line has been given a name.

When I hover over a line, is it possible to access the name of the line in the tooltip, without hardcoding it into the tooltip?

For example:

import sys
import os
import bokeh
import pandas as pd
from collections import OrderedDict

bokeh.io.output_notebook()

x = [0,1,2,3,4]
y1 = [0, 3.5, 8, 4, 5]
y2 = [100, 110, 200, 90, 30.5]

df = pd.DataFrame(data={'x':x, 'y1':y1, 'y2':y2})

f = bokeh.plotting.figure(plot_width=900, plot_height=400)

ds = bokeh.models.ColumnDataSource(df)

line1 = f.line('x', 'y1', source=ds, name='line1', color='blue')
line2 = f.line('x', 'y2', source=ds, name='line2', color='red')

htool = bokeh.models.HoverTool(mode='mouse', line_policy='interp', tooltips=OrderedDict([('x', '@x'), ('Mouse y', 'y'\), \('Value:', '~y'), ('Line Name:', '@NAME')]))
f.add_tools(htool)

bokeh.io.show(f)

Is there some parameter that can be added to the tooltip to display 'line1' or 'line2' when the user mouses over one of the lines?

Also, I have seen code snippets where people use $~y in the tooltip (the tilde). I cannot see documentation about that anywhere. It seems to display the actual value of the line or marker, but am I correct in saying that?

Thanks,
Adrian.

--
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/ed74c902-2576-47a6-ae64-4996691bf6c1%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

thanks for the response. The problem I have is that there could be any number of curves and each one typically has thousands of data points associated with it, so the html file might get very large and unwieldy.

I will add 2 new issues to Github.

Regards,

Adrian.