import param import numpy as np import holoviews as hv hv.extension('bokeh', 'matplotlib') from holoviews import streams listing = ', '.join(sorted([str(s.name) for s in param.descendents(streams.LinkedStream)])) print('The linked stream classes supported by HoloViews are:\n\n{listing}'.format(listing=listing)) pointer = streams.PointerXY() print(pointer.source) print('The %s stream has contents %r' % (pointer, pointer.contents)) pointer_dmap = hv.DynamicMap(lambda x, y: hv.Points([(x, y)]), streams=[pointer]) print(pointer.source is pointer_dmap) pointer_dmap.options(size=10) pointer.contents %%opts Area (color='#fff8dc' line_width=2) Curve (color='black') VLine (color='red') xs = np.linspace(-3, 3, 400) def function(xs, time): "Some time varying function" return np.exp(np.sin(xs+np.pi/time)) def integral(limit, time): limit = -3 if limit is None else np.clip(limit,-3,3) curve = hv.Curve((xs, function(xs, time)))[limit:] area = hv.Area ((xs, function(xs, time)))[:limit] summed = area.dimension_values('y').sum() * 0.015 # Numeric approximation return (area * curve * hv.VLine(limit) * hv.Text(limit + 0.8, 2.0, '%.2f' % summed)) hv.DynamicMap(integral, streams=[streams.Stream.define('Time', time=1.0)(), streams.PointerX().rename(x='limit')]) xvals = np.linspace(0,4,202) ys,xs = np.meshgrid(xvals, -xvals[::-1]) img = hv.Image(np.sin(((ys)**3)*xs)) pointer = streams.PointerXY(x=0,y=0, source=img) pointer_dmap = hv.DynamicMap(lambda x, y: hv.Points([(x, y)]), streams=[pointer]) img + pointer_dmap.options(size=10) %%opts Curve {+framewise} hv.DynamicMap(lambda x, y: img.sample(y=np.clip(y,-.49,.49)), streams=[pointer]) +\ hv.DynamicMap(lambda x, y: img.sample(x=np.clip(x,-.49,.49)), streams=[pointer]) pointer = streams.PointerXY(x=0, y=0) cross_dmap = hv.DynamicMap(lambda x, y: (hv.VLine(x) * hv.HLine(y)), streams=[pointer]) cross_dmap + cross_dmap.clone(link_inputs=False) tap = streams.SingleTap(transient=True) double_tap = streams.DoubleTap(rename={'x': 'x2', 'y': 'y2'}, transient=True) taps = [] def record_taps(x, y, x2, y2): if None not in [x,y]: taps.append((x, y, 1)) elif None not in [x2, y2]: taps.append((x2, y2, 2)) return hv.Points(taps, vdims='Taps') %%opts Points [color_index='Taps' tools=['hover']] (size=10 cmap='Set1') hv.DynamicMap(record_taps, streams=[tap, double_tap]) taps