I'm trying to select the line for which my hover appears with vline
mode.
Here's example (taken from this SO question):
days = ['2018/1/1', '2018/1/2', '2018/1/3', '2018/1/4', '2018/1/5']
data_a = [10, 34, 23, 14, 58]
data_b = [20, 13, 45, 98, 65]
data_c = [20, 23, 43, 76, 57]
df_plot = pd.DataFrame({'A': data_a, 'B': data_b, 'C': data_c}, index=days)
df_plot['dates'] = pd.to_datetime(df_plot.index, format='%Y/%m/%d')
source = ColumnDataSource(df_plot)
p = figure(x_axis_type="datetime")
p.line('dates', 'A', source=source, color='red')
p.line('dates', 'B', source=source, color='blue')
p.line('dates', 'C', source=source, color='green')
p.add_tools(HoverTool(tooltips=[("A", "@A"), ("B", "@B"), ("C", "@C")],mode = "vline"))
show(p)
The image hover appears for all the lines, how can I do if I want the hover only on the red line ?
If I understood well you can set the attribute renderers
to the HoverTool
So try this:
red_renderer_line = p.line('dates', 'A', source=source, color='red')
p.line('dates', 'B', source=source, color='blue')
p.line('dates', 'C', source=source, color='green')
p.add_tools(
HoverTool(
tooltips=[("A", "@A"), ("B", "@B"), ("C", "@C")],mode = "vline"
renderers=[red_renderer_line]
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With