0

I am using Bokeh and want to display 3 lines plots on the same figure. Additionally, each line plot to have a hovertool which will display a variable for each (x, y) location on the line. Furthermore, each line plot has a different length.

This implementation for 1 Hovertool worked perfectly:

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)

which produced Curve using 1 Hovertool

However when trying to use the same method with 3 Hovertools not of the Hovertools rendered in. Implemented as:

# 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, plot_height=700, tools=[hover1, hover2, hover3],
                  title="Curve for 1, 2 and 3")

plot.x_range = Range1d(0.0, 1.0)
plot.y_range = Range1d(0.0, 1.0)

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

show(plot)

which produced Curve using 3 Hovertools where each hovertool's icon is present on the left of the figure yet nothing displays when hovering over any of the line plots.

Similarly, in an alternatice implmentation as described in (Multiple HoverTools for different lines (bokeh)) the figure also displays the lines correctly but does not show any Hovertools at all. Implemented as:

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

plot = figure(plot_width=700, plot_height=700, title="Curve for 1, 2 and 3")

plot.x_range = Range1d(0.0, 1.0)
plot.y_range = Range1d(0.0, 1.0)

r1 = plot.line('x1', 'y1', line_width=3, source=source1, line_color="blue", legend_label="line1")
plot.add_tools(HoverTool(renderers=[r1], tooltips=[("x1: ", "$x1"), ("y1: ", "$y1"), ("score1", "@desc1")]))

r2 = plot.line('x2', 'y2', line_width=3, source=source2, line_color="red", legend_label="line2")
plot.add_tools(HoverTool(renderers=[r2], tooltips=[("x2: ", "$x2"), ("y2: ", "$y2"), ("score2", "@desc2")]))

r3 = plot.line('x3', 'y3', line_width=3, source=source3, line_color="green", legend_label="line3")
plot.add_tools(HoverTool(renderers=[r3], tooltips=[("x3: ", "$x3"), ("y3: ", "$y3"), ("score3", "@desc3")]))

show(plot)

0 Answers0