NdLayout Container
In [1]:
import numpy as np
import holoviews as hv

An NdLayout is a multi-dimensional dictionary of HoloViews elements presented side-by-side like a Layout . An NdLayout can be considered as a special-case of HoloMap that can hold any one type of HoloViews container or element as long as it isn't another NdLayout or Layout . Unlike a regular Layout that can be built with the + operator, the items in an NdOverlay container have corresponding keys and must all have the same type. See the Building Composite Objects user guide for details on how to compose containers.

NdLayout holds dictionaries

Using the sine_curve function below, we can declare a dictionary of Curve elements, where the keys correspond to the frequency values:

In [2]:
frequencies = [0.5, 0.75, 1.0, 1.25]

def sine_curve(phase, freq):
    xvals = [0.1* i for i in range(100)]
    return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))

curve_dict = {f:sine_curve(0,f) for f in frequencies}

We now have a dictionary where the frequency is the key and the corresponding curve element is the value. We can now turn this dictionary into an NdLayout by declaring the keys as corresponding to the frequency key dimension:

In [3]:
NdLayout = hv.NdLayout(curve_dict, kdims=['frequency'])

NdLayout is multi-dimensional

By using tuple keys and making sure each position in the tuple is assigned a corresponding kdim , NdLayouts allow visualization of a multi-dimensional space:

In [4]:
curve_dict_2D = {(p,f):sine_curve(p,f) for p in [0, np.pi/2] for f in [0.5, 0.75]}
NdLayout = hv.NdLayout(curve_dict_2D, kdims=['phase', 'frequency'])

NdLayout is similar to HoloMap

Other than the difference in the visual semantics, whereby NdLayout displays its contents overlaid, NdLayout are very similar to HoloMap (see the HoloMap notebook for more information).

One way to demonstrate the similarity of these two containers is to cast our NdLayout object to HoloMap :

In [5]:

We could now cast this HoloMap back to an NdLayout . Unlike the other container examples such as GridSpace and NdOverlay , we cannot display this reconstituted NdLayout next to the HoloMap above using + as a Layout cannot hold an NdLayout in the same way than an NdLayout cannot hold a Layout .

Download this notebook from GitHub (right-click to download).