如何在python中链接几个散景/全息视图/面板对象的悬停?

问题描述

是否可以“链接”两个散景/全息对象的悬停,以便同时显示悬停在两个对象上?

这是我想要实现的示例:

enter image description here

目前我只能在其中一个图像上显示悬停,而不能同时在两个图像上显示

enter image description here

请在下面找到我用来生成最后一张图的可重现代码

import xarray as xr
import hvplot.xarray  # noqa

import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

import panel as pn
import panel.widgets as pnw
pn.extension()

from bokeh.models import HoverTool

# Load tutorial xarray air dataset
air_ds = xr.tutorial.open_dataset('air_temperature').load()

# Create two different datasets based on the yearly mean and standard deviation of the  air temperature
meanairbyyear = air_ds.air.groupby('time.year').mean()
stdairbyyear = air_ds.air.groupby('time.year').std()
meanair2d = xr.Dataset(
    {
        "y2013": (["lat","lon"],meanairbyyear[0,:,:]),"y2014": (["lat",meanairbyyear[1,},coords={
        "lon": ("lon",meanairbyyear.lon),"lat": ("lat",meanairbyyear.lat),)
stdair2d = xr.Dataset(
    {
        "y2013": (["lat",stdairbyyear[0,stdairbyyear[1,stdairbyyear.lon),stdairbyyear.lat),)

# Define panel object
variable_type = ('y2013','y2014')

variables  = pnw.RadioButtonGroup(name='Variable',value='y2014',options=list(variable_type))

def plot_map_mean(var):
    plt = meanair2d[var].hvplot.contourf(width=400)
    # Hover
    MyHover = HoverTool(
        tooltips=[
            ( 'Lon',' $x'),( 'Lat',' $y'),( var + ' Mean','@' + var),],formatters={
            '$x' : 'numeral','$y' : 'numeral','@' + var : 'numeral',point_policy="follow_mouse"
    )
    plt.opts(tools = [MyHover])
    return plt

def plot_map_std(var):
    plt = stdair2d[var].hvplot.contourf(width=400)
    # Hover
    MyHover = HoverTool(
        tooltips=[
            ( 'Lon',( var + ' Std',point_policy="follow_mouse"
    )
    plt.opts(tools = [MyHover])
    return plt

@pn.depends(variables)
def reactive_mean_plot(variables):
    return plot_map_mean(variables)

@pn.depends(variables)
def reactive_std_plot(variables):
    return plot_map_std(variables)

widgets   = pn.Column("<br>\n# Years",variables)
contour_pn = pn.Column(widgets,pn.Column("<br>\n### Mean",reactive_mean_plot),pn.Column("<br>\n### Std",reactive_std_plot)
                      )
contour_pn

解决方法

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

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

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