Is there a way to create two dynamicmaps and have them control each other?

Here, tap on image, get a timeseries at the nearest coordinate tapped, but is it possible to also tap on the timeseries and get the nearest time image?

import xarray as xr
import holoviews as hv

hv.extension("bokeh")

ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))

source = hv.Image(ds.isel(time=0), ["lon", "lat"], ["air"])
stream = hv.streams.Tap(source=source, x=-88 + 360, y=40)

def create_timeseries(x, y):
    ds_sel = ds.sel(lon=x, lat=y, method="nearest")
    return hv.Curve(ds_sel, ["time"], ["air"])

target = hv.DynamicMap(create_timeseries, streams=[stream]).opts(framewise=True)
source + target

Sure, same approach:


ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))

coord_stream = hv.streams.Tap(x=-88 + 360, y=40)
time_stream = hv.streams.Tap(x=ds.time.values[0])

def create_timeseries(x, y):
    return hv.Curve(ds.sel(lon=x, lat=y, method="nearest"), "time", "air")

def create_image(x, y):
    return hv.Image(ds.sel(time=x, method='nearest'), ["lon", "lat"], "air")

timeseries = hv.DynamicMap(create_timeseries, streams=[coord_stream]).opts(framewise=True, tools=['tap'])
image = hv.DynamicMap(create_image, streams=[time_stream]).opts(tools=['tap'])

coord_stream.source = image
time_stream.source = timeseries 

image + timeseries
1 Like