import numpy as np
import holoviews as hv
hv.extension('bokeh')
A DynamicMap is an explorable multi-dimensional wrapper around a callable that returns HoloViews objects. A DynamicMap
callable cannot return Layouts
, NdLayouts
, GridSpaces
or other DynamicMaps
or HoloMaps
but can contain any other HoloViews object. See the Building Composite Objects user guide for details on how to compose containers and for the user-guide describing DynamicMap
in more detail, see the Live Data user guide.
DynamicMap
holds callables¶Although a DynamicMap
holds a user supplied callable, this can be seen as as a generalization of HoloMap
which holds dictionaries of elements: the key is then conceptually the arguments to the callable and the value is the object the callable returns. This conceptual model assume the callable is a true function where a set of arguments always maps to the same output, no matter how many times it is called.
For HoloMap
, we used the sine_curve
function below to generate a dictionary of Curve
objects. With DynamicMap
, we can use it directly:
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]))
# When run live, this cell's output should match the behavior of the GIF below
dmap = hv.DynamicMap(sine_curve, kdims=['phase', 'frequency'])
dmap.redim.range(phase=(0.5,1), frequency=(0.5,1.25))
Unlike a HoloMap
which is limited by the static number of items in the supplied dictionary (which must all exist in memory at once), this DynamicMap
lets you pick any phase or frequency within the supplied range.
Although DynamicMap
is designed as the dynamic counterpart of HoloMap
, the fact that it accepts a code specification as opposed to data opens up a large set of new possibilities. The Live Data user guide is dedicated to exploring what can be done with DynamicMap
.