没有在图形上呈现的用于不同线条的多个HoverTools

问题描述

我正在使用bokeh,想在同一张图上显示3条线图。此外,每个折线图都有一个悬停工具,该工具将为该线上的每个(x,y)位置显示一个变量。 此外,每个线图都有不同的长度。

用于1个Hovertool的此实施效果很好:

source = ColumnDataSource(data=dict(x=xdata,y=ydata,desc=descdata,))

hover = HoverTool(tooltips=[("x: ","$x"),("y: ","$y"),("score","@desc"),])
plot = figure(plot_width=700,plot_height=700,tools=[hover])

plot.x_range = Range1d(0.0,1.0)
plot.y_range = Range1d(0.0,1.0)
plot.line('x','y',line_width=3,source=source)

show(plot)

产生了Curve using 1 Hovertool

但是,当尝试对3个Hovertools使用相同的方法时(不是呈现的Hovertools)。 实施为:

# dataxX and datayX are not consistent lengths across sources
source1 = ColumnDataSource(data=dict(x1=datax1,y1=datay1,desc1=descdata1))
source2 = ColumnDataSource(data=dict(x2=datax2,y2=datay2,desc2=descdata2))
source3 = ColumnDataSource(data=dict(x3=datax3,y3=datay3,desc3=descdata3))

# create over tools for each source
hover1 = HoverTool(tooltips=[("x1: ","$x1"),("y1: ","$y1"),("score1","@desc1")])
hover2 = HoverTool(tooltips=[("x2: ","$x2"),("y2: ","$y2"),("score2","@desc2")])
hover3 = HoverTool(tooltips=[("x3: ","$x3"),("y3: ","$y3"),("score3","@desc3")])

plot = figure(plot_width=700,tools=[hover1,hover2,hover3],title="Curve for 1,2 and 3")

plot.x_range = Range1d(0.0,1.0)

plot.line('x1','y1',source=source1,line_color="blue",legend_label="line1")
plot.line('x2','y2',source=source2,line_color="red",legend_label="line2")
plot.line('x3','y3',source=source3,line_color="green",legend_label="line3")

show(plot)

产生了Curve using 3 Hovertools,其中每个悬停工具的图标都出现在图的左侧,但是将鼠标悬停在任何折线图上时都不会显示任何内容

类似地,在(Multiple HoverTools for different lines (bokeh))中所述的替代实施中,该图还正确显示了线条,但根本没有显示任何悬停工具。 实施为:

# dataxX and datayX are not consistent lengths across sources
source1 = ColumnDataSource(data=dict(x1=datax1,desc3=descdata3))

plot = figure(plot_width=700,1.0)

r1 = plot.line('x1',legend_label="line1")
plot.add_tools(HoverTool(renderers=[r1],tooltips=[("x1: ","@desc1")]))

r2 = plot.line('x2',legend_label="line2")
plot.add_tools(HoverTool(renderers=[r2],tooltips=[("x2: ","@desc2")]))

r3 = plot.line('x3',legend_label="line3")
plot.add_tools(HoverTool(renderers=[r3],tooltips=[("x3: ","@desc3")]))

show(plot)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)