I have multiple figures, sharing y-axis but not the x-axis. When my cursor hover on one figure, it will tell me the values (x & y-axis values). But Others have no tooltips. I want all figures show tooltips simultaneously when cursor hover any figure where the CrosshairTool intersect lines.
Below, I posted the sample code that gives me result shown on the left.
The image showing what I am getting with the code, and what I want
Any help is highly appreciated!
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.layouts import row
from bokeh.models import HoverTool, CrosshairTool, ColumnDataSource, Span
df = pd.DataFrame({
'depth': np.linspace(1000,1100,201),
'x1': np.linspace(80,90,201)+np.random.rand(201),
'x2': np.linspace(2.5,3.5,201)+np.random.rand(201)/10
})
source = ColumnDataSource(df)
p1 = figure(y_range=(df['depth'].max(),df['depth'].min()),
width=400,height=600,y_axis_label='Depth (m)')
p2 = figure(y_range=p1.y_range,width=400, height=600)
p1.line('x1','depth',source=source, line_width=2, color='blue')
p2.line('x2','depth',source=source, line_width=2, color='green')
hover1 = HoverTool(
tooltips=[('', '@depth{0.0} m'),('', '@x1{0.0} °C')],
mode='hline',attachment="above"
)
hover2 = HoverTool(
tooltips=[('','@depth{0.00} m'),('','@x2{0.00} µs/ft')],
mode='hline',attachment="above"
)
xspan = Span(dimension="width",line_width=0.5)
p1.add_tools(CrosshairTool(overlay=xspan))
p2.add_tools(CrosshairTool(overlay=xspan))
p1.add_tools(hover1)
p2.add_tools(hover2)
layout = row(p1,p2)
show(layout)
Tooltipcan be attached to a plot canvas (and then controlled viaCustomJS). But I don't actually personally know how to do it, or know of an example to point to. Beside that, you'd also be responsible for all the CDS lookup, etc. since none of the internal "templating" for the built-in hover tool is public API. Although it is not a short-term solution I would encourage you to open a github issue abiout linked hover.