Holoviews interactive plot of gridded data with slider on top

This code creates an interactive plot with Holoviews:

import numpy as np
import xarray as xr
import holoviews as hv
hv.extension('bokeh')

# Create sample data
x = np.linspace(-10, 10, 10)
y = np.linspace(-10, 10, 10)
time = np.arange(0, 10, 1)
data = np.random.rand(len(time), len(x), len(y))

# Create xarray DataFrame
ds = xr.DataArray(data, coords=[time, x, y], dims=['time', 'x', 'y'], name='data').to_dataset()

# Create Holoviews Dataset
hv_ds = gv.Dataset(ds, kdims=['time', 'y', 'x'], vdims=['data'])

#plot with slider
hv_ds.to(gv.Image, ['x', 'y'])

It creates a gridded plot of the data with a slider that moves through the time dimension. By default, the slider is placed on the right.

How can I move the slider so it is on top of the plot?

>Solution :

For full layout control, you can use Panel directly, but for simply selecting a different location you can set hv.output(widget_location=<option>) where the valid <option>s are:

['left', 'bottom', 'right', 'top', 'top_left', 'top_right',
 'bottom_left', 'bottom_right', 'left_top', 'left_bottom',
 'right_top', 'right_bottom']

Leave a Reply