NdOverlay#

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


Title
NdOverlay Container
Dependencies
Bokeh
Backends
Bokeh
Matplotlib
Plotly
import numpy as np
import holoviews as hv
hv.extension('bokeh')

An NdOverlay is a multi-dimensional dictionary of HoloViews elements presented overlaid in the same space. An NdOverlay can be considered as a special-case of HoloMap that can only hold a single type of element at a time. Unlike a regular Overlay 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.

NdOverlay holds dictionaries#

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

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 NdOverlay by declaring the keys as corresponding to the frequency key dimension:

ndoverlay = hv.NdOverlay(curve_dict, kdims='frequency')
ndoverlay

Note that the NdOverlay is displayed with a legend using colors defined by the Curve color cycle. For more information on using Cycle to define color cycling, see the User Guide.

NdOverlay is multi-dimensional#

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

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

NdOverlay is similar to HoloMap#

Other than the difference in the visual semantics, whereby NdOverlay displays its contents overlaid, NdOverlay 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 ndoverlay object to HoloMap and back to an NdOverlay:

hmap = hv.HoloMap(ndoverlay)
hmap + hv.NdOverlay(hmap)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

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