是否可以“链接”两个散景/全息对象的悬停,以便同时显示两个对象上的悬停?
这是我想要实现的示例:
目前我只能在其中一个图像上显示悬停,但不能同时在两个图像上显示:
请在下面找到我用来生成最后一个数字的可重现代码。
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", "lon"], meanairbyyear[1,:,:]),
},
coords={
"lon": ("lon", meanairbyyear.lon),
"lat": ("lat", meanairbyyear.lat),
},
)
stdair2d = xr.Dataset(
{
"y2013": (["lat", "lon"], stdairbyyear[0,:,:]),
"y2014": (["lat", "lon"], stdairbyyear[1,:,:]),
},
coords={
"lon": ("lon", stdairbyyear.lon),
"lat": ("lat", 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', ' $x'),
( 'Lat', ' $y'),
( var + ' Std', '@' + var),
],
formatters={
'$x' : 'numeral',
'$y' : 'numeral',
'@' + var : 'numeral',
},
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