Search code examples
pythonholoviews

How to show two slices of an HoloMap side by side with only one slider for the remaining kdim?


I have 2D data with 2 kdims. I want to select two slices of one of the kdims and show them side by side with a slider for the other dimension.

The .grid layout has the desired function but shows all elements of the remaining dimension and has wrong shape.

Is it possible to to remove the kdim that has been sliced from the plot while using standard HoloMaps?

# my code from Jupyter notebook
import numpy as np
import holoviews as hv
import matplotlib.pyplot as plt
hv.extension('bokeh', 'matplotlib')

dat = np.random.randn(3,4,40,20) 
p=[100,200,300]
f=[1,2,3,4]
px = np.arange(40)
py = np.arange(20)
ds = hv.Dataset(( py, px, f, p, dat), ['px', 'py', 'f', 'p'], 'data')
im=ds.to(hv.Image).options(width=150, aspect="equal")

#this works:
im.select(p=100) + im.select(p=100) 

#this works not:
im.select(p=100) + im.select(p=200) 

#this works but has wrong shape and shows 3 plots:
im.grid('p')

ds0 = hv.Dataset(( py, px, f, dat[0,:,:,:]), ['px', 'py', 'f'], 'p100')
ds1 = hv.Dataset(( py, px, f, dat[1,:,:,:]), ['px', 'py', 'f'], 'p200')
im0=ds0.to(hv.Image).options(width=150, aspect="equal")
im1=ds1.to(hv.Image).options(width=150, aspect="equal")

# this works but the information about the selection is gone:
im0+im1

im.select(p=100) + im.select(p=100) shows two plots with only the selector for f. This is what I want but for different p. If I select a different slice like here: im.select(p=100) + im.select(p=200) I get a second slider for p and always only one plot is shown.


Solution

  • im.layout('p')
    

    This shows all slices, but you can select the ones you want like you would in a HoloMap.