Holoviews to HoloViews

Interacting between HoloViews objects.


  • Dynamically generate values

  • All in Python


  • Interactivity may not be retained when saved

  • May require backend server


Tap for update plot

Server required.

import xarray as xr
import holoviews as hv


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_geomap(x, y):
    ds_sel = ds.sel(time=x, method="nearest")
    return hv.Image(ds_sel, ["lon", "lat"], ["air"]).opts(
        "Image", title=str(x)[:16], tools=["tap", "hover"])

def create_timeseries(x, y):
    ds_sel = ds.sel(lon=x, lat=y, method="nearest")
    return hv.Curve(ds_sel, ["time"], ["air"]).opts(
        "Curve", title=f"{x:.1f}, {y:.1f}", framewise=True, tools=["tap", "hover"])

def create_point(x, y):
    return hv.Points((x, y)).opts("Points", color="red", marker="x", size=25)

def create_vline(x, y):
    return hv.VLine(x).opts("VLine", color="red")

# create base plots
geomap = hv.DynamicMap(create_geomap, streams=[time_stream])
timeseries = hv.DynamicMap(create_timeseries, streams=[coord_stream])

# link source
coord_stream.source = geomap
time_stream.source = timeseries

# create annotations
coord_point = hv.DynamicMap(create_point, streams=[coord_stream])
time_vline = hv.DynamicMap(create_vline, streams=[time_stream])

# overlay + layout
layout = geomap * coord_point + timeseries * time_vline