In [ ]:
import numpy as np
import holoviews as hv
hv.extension('matplotlib')
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.
Using the sine_curve function below, we can declare a dictionary of Curve elements, where the keys correspond to the frequency values:
In [ ]:
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 [ ]:
NdLayout = hv.NdLayout(curve_dict, kdims='frequency')
NdLayout
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 [ ]:
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
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 [ ]:
hv.HoloMap(NdLayout)