仅在具有散景的选定行上悬停

时间:2018-09-21 22:19:39

标签: python visualization bokeh

我正在尝试选择vline模式下悬停显示的行。

以下是示例(来自this SO问题)

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

图像悬停出现在所有行上,如果我只想将悬停在红线上怎么办?

1 个答案:

答案 0 :(得分:2)

如果我了解得很好,则可以设置属性renderers to the HoverTool

所以尝试一下:

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]
    )
)