Python 用于不同线的多个悬停工具(bokeh)

Python 用于不同线的多个悬停工具(bokeh),python,python-3.x,hover,bokeh,Python,Python 3.x,Hover,Bokeh,我在bokeh绘图上有多行,我希望HoverTool显示每行的值,但使用上一个stackoverflow答案中的方法不起作用: 下面是该答案的相关代码片段: fig = bp.figure(tools="reset,hover") s1 = fig.scatter(x=x,y=y1,color='#0000ff',size=10,legend='sine') s1.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"} s2 =

我在bokeh绘图上有多行,我希望HoverTool显示每行的值,但使用上一个stackoverflow答案中的方法不起作用:

下面是该答案的相关代码片段:

fig = bp.figure(tools="reset,hover")
s1 = fig.scatter(x=x,y=y1,color='#0000ff',size=10,legend='sine')
s1.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
s2 = fig.scatter(x=x,y=y2,color='#ff0000',size=10,legend='cosine')
fig.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
这是我的代码:

from bokeh.models import HoverTool
from bokeh.plotting import figure

source = ColumnDataSource(data=dict(
    x = [list of datetimes]
    wind = [some list]
    coal = [some other list]
    )
)

hover = HoverTool(mode = "vline")

plot = figure(tools=[hover], toolbar_location=None,
    x_axis_type='datetime')

plot.line('x', 'wind')
plot.select(dict(type=HoverTool)).tooltips = {"y":"@wind"}
plot.line('x', 'coal')
plot.select(dict(type=HoverTool)).tooltips = {"y":"@coal"}

据我所知,它相当于我链接到的答案中的代码,但当我将鼠标悬停在图形上时,两个悬停工具框显示相同的值,即
风的值,您需要为每个绘图添加渲染器。看看这个。也不要对两个值使用相同的
y标签
,更改名称

from bokeh.models import HoverTool
from bokeh.plotting import figure

source = ColumnDataSource(data=df)

plot = figure(x_axis_type='datetime',plot_width=800, plot_height=300)

plot1 =plot.line(x='x',y= 'wind',source=source,color='blue')
plot.add_tools(HoverTool(renderers=[plot1], tooltips=[('wind',"@wind")],mode='vline'))

plot2 = plot.line(x='x',y= 'coal',source=source,color='red')
plot.add_tools(HoverTool(renderers=[plot2], tooltips=[("coal","@coal")],mode='vline'))

show(plot)
输出如下所示。

谢谢,这很有效。它还与我链接的页面上的另一个答案联系在一起:@user3087409是的,基本概念是相同的,而解决方案是针对这个问题的。你还说这对你没用。因此,将代码更改为您的场景并发布。