holoviews icon indicating copy to clipboard operation
holoviews copied to clipboard

Include label in hover tool

Open neighthan opened this issue 6 years ago • 3 comments
trafficstars

It would be nice to be able to easily include the label for a given, e.g., Curve in the hovertool. I tried doing so like this

import numpy as np
import holoviews as hv
from bokeh.models import HoverTool

hv.extension("bokeh")
hover = HoverTool(tooltips=[("label", "$name"), ("x", "@x"), ("y", "@y")])
hv.opts.defaults(hv.opts.Curve(tools=[hover]))

x = np.linspace(-5, 5, 101)
hv.Curve((x, np.sin(x)), label="sin") * hv.Curve((x, np.cos(x)), label="cos")

but my hovertool looks like:

image

It does seem like there is a name attribute, because if I do

hover = HoverTool(tooltips=[("label", "$random_thing"), ("x", "@x"), ("y", "@y")])

instead, the hovertool doesn't work at all. Perhaps the label from the hv.Curve needs to be passed back to a bokeh glyph for this to work? Or is there a different way that I could reference the label in the hovertool?

neighthan avatar Apr 03 '19 17:04 neighthan

One solution

import hvplot.pandas
import pandas as pd
import numpy as np

x = np.linspace(-5, 5, 101)
df = pd.DataFrame({'sin': np.sin(x), 'cos': np.cos(x), 'x': x}).melt(
    id_vars='x', value_name='y', var_name='label')
df.hvplot('x', 'y', groupby='label').overlay('label')

image

ahuang11 avatar Apr 05 '19 17:04 ahuang11

ahuang11's solution is not good for me since I would need to create a column containing the line series name.

My preference: Since there is already an existing label= parameter that you can pass into a hvplot call and is being used by the legend, similarly the tooltip, should just grab that to be default "label" as well.

pybokeh avatar May 21 '20 15:05 pybokeh

If present, I think including the label and group should be the default behavior for the hover tooltips.

droumis avatar Feb 20 '24 19:02 droumis