import numpy as np import holoviews as hv from holoviews import opts hv.extension('matplotlib') xvals = np.linspace(-4, 0, 202) yvals = np.linspace(4, 0, 202) xs, ys = np.meshgrid(xvals, yvals) def waves_image(alpha, beta): return hv.Image(np.sin(((ys/alpha)**alpha+beta)*xs)) waves_image(1,0) + waves_image(1,4) dmap = hv.DynamicMap(waves_image, kdims=['alpha', 'beta']) dmap dmap[1,2] + dmap.select(alpha=1, beta=2) dmap.redim.range(alpha=(1, 5.0), beta=(1, 6.0)) dmap.redim.values(alpha=[1, 2, 3], beta=[0.1, 1.0, 2.5]) dmap.current_key def shapes(N, radius=0.5): # Positional keyword arguments are fine paths = [hv.Path([[(radius*np.sin(a), radius*np.cos(a)) for a in np.linspace(-np.pi, np.pi, n+2)]], extents=(-1,-1,1,1)) for n in range(N,N+3)] return hv.Overlay(paths) holomap = hv.HoloMap({(N,r):shapes(N, r) for N in [3,4,5] for r in [0.5,0.75]}, kdims=['N', 'radius']) dmap = hv.DynamicMap(shapes, kdims=['N','radius']) holomap + dmap dtype = type(dmap.data).__name__ length = len(dmap.data) print("DynamicMap 'dmap' has an {dtype} .data attribute of length {length}".format(dtype=dtype, length=length)) hv.HoloMap(dmap) hv.HoloMap(dmap[{(2,0.3), (2,0.6), (3,0.3), (3,0.6)}]) samples = hv.HoloMap(dmap[{2,3},{0.5,1.0}]) samples samples.data.keys() from holoviews.util import Dynamic dynamic = Dynamic(samples) print('After apply Dynamic, the type is a {dtype}'.format(dtype=type(dynamic).__name__)) dynamic dmap = hv.DynamicMap(shapes, kdims=['N','radius']).redim.range(N=(2,20), radius=(0.5,1.0)) sliced = dmap[4:8, :] sliced sliced[:, 0.8:1.0] xs = np.linspace(0, 2*np.pi,100) def sin(ph, f, amp): return hv.Curve((xs, np.sin(xs*f+ph)*amp)) kdims=[hv.Dimension('phase', range=(0, np.pi)), hv.Dimension('frequency', values=[0.1, 1, 2, 5, 10]), hv.Dimension('amplitude', values=[0.5, 5, 10])] waves_dmap = hv.DynamicMap(sin, kdims=kdims) wave_grid = waves_dmap.overlay('amplitude').grid('frequency') wave_grid.opts(fig_size=200, show_legend=True) opts.defaults(opts.Path(color=hv.Palette('Blues'))) def spiral_equation(f, ph, ph2): r = np.arange(0, 1, 0.005) xs, ys = (r * fn(f*np.pi*np.sin(r+ph)+ph2) for fn in (np.cos, np.sin)) return hv.Path((xs, ys)) spiral_dmap = hv.DynamicMap(spiral_equation, kdims=['f','ph','ph2']) spiral_dmap = spiral_dmap.redim.values( f=np.linspace(1, 10, 10), ph=np.linspace(0, np.pi, 10), ph2=np.linspace(0, np.pi, 4)) spiral_grid = spiral_dmap.groupby(['f', 'ph'], group_type=hv.NdOverlay, container_type=hv.GridSpace) spiral_grid.opts( opts.GridSpace(xaxis=None, yaxis=None), opts.Path(bgcolor='white', xaxis=None, yaxis=None)) ls = np.linspace(0, 10, 200) xx, yy = np.meshgrid(ls, ls) def cells(time): return hv.Image(time*np.sin(xx+time)*np.cos(yy+time), vdims='Intensity') dmap = hv.DynamicMap(cells, kdims='time').redim.range(time=(1,20)) (dmap + dmap.redim.range(Intensity=(0,10))).opts( opts.Image(axiswise=True))