Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover only on selected lines with Bokeh

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)

enter image description here

The image hover appears for all the lines, how can I do if I want the hover only on the red line ?

like image 692
Adrien Pacifico Avatar asked Mar 05 '23 09:03

Adrien Pacifico


1 Answers

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]
    )
)
like image 176
ChesuCR Avatar answered Mar 16 '23 19:03

ChesuCR