如何同时触发多个散景图中的悬停(和工具提示)?

问题描述 投票:0回答:1

我有多个图形,共享 y 轴但不共享 x 轴。当我的光标悬停在一个图上时,它会告诉我这些值(x 和 y 轴值)。但其他人没有工具提示。我希望当光标悬停在 CrosshairTool 与线相交的任何图形时,所有图形同时显示工具提示。

下面,我发布了示例代码,其结果如左侧所示。

该图像显示了我通过代码得到的内容以及我想要的内容

非常感谢任何帮助!

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)
python frontend hover bokeh inspection
1个回答
0
投票
import bokeh
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource

df = [***dataframe with columns***]

data_source = ColumnDataSource(df)

TOOLS = 'box_select, lasso_select, wheel_zoom, pan, save, undo, redo, reset'

reachability_plot = figure(plot_width=2500, plot_height=500, y_axis_label='Reachability Distance', x_axis_label='Samples',
                            tools=TOOLS)
reachability_plot.circle('Samples', 'Reachability', size=4, fill_alpha=1, source=data_source, selection_color='red')

neu_den = figure(plot_width=1100, plot_height=400, y_axis_label='RHOB', x_axis_label='NPSS', tools=TOOLS,
                    x_range=(0, 0.6), y_range=(2.7, 1.8))
neu_den.circle('NPSS', 'RHOB', size=5, fill_alpha=0.3, source=data_source, selection_color='red')

gr_rhob = figure(plot_width=1100, plot_height=400, y_axis_label='GR_N', x_axis_label='RHOB', tools=TOOLS,
                    x_range=(1.8, 2.7), y_range=(0, 150))
gr_rhob.circle('RHOB', 'GR_N', size=5, fill_alpha=0.3, source=data_source, selection_color='red')

def get_df_name(df):
    name = [x for x in globals() if globals()[x] is df][0]
    return name

TITLE = "OPTICS " + str(get_df_name(df))
bokeh.io.output_file(filename="OPTICS_Visualization.html", title=TITLE)

grid = gridplot([[reachability_plot], [neu_den], [gr_rhob]])
show(grid)
© www.soinside.com 2019 - 2024. All rights reserved.