0

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)
3
  • Bokeh does not currently have a linked hover between plots. Commented Sep 6, 2024 at 16:06
  • @bigreddot thanks for the comment, would it be possible to get it done with JS callbacks? Any direction towards the solution is highly appreciated. Commented Sep 7, 2024 at 6:56
  • In principle, a bare Tooltip can be attached to a plot canvas (and then controlled via CustomJS). 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. Commented Sep 11, 2024 at 16:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.