- A linked streams example demonstrating how to use the PolyDraw stream.
- streams, linked, position, interactive
import numpy as np import holoviews as hv from holoviews import streams from matplotlib.path import Path hv.extension('bokeh')
stream adds a bokeh tool to the source plot, which allows drawing, dragging and deleting polygons and making the drawn data available to Python. The tool supports the following actions:
Double tap to add the first vertex, then use tap to add each subsequent vertex, to finalize the draw action double tap to insert the final vertex or press the ESC key to stop drawing.
Tap and drag an existing patch/multi-line, the point will be dropped once you let go of the mouse button.
Tap a patch/multi-line to select it then press BACKSPACE key while the mouse is within the plot area.
As a simple example we will create simple
elements and attach each to a
stream. We will also enable the
option on the stream to enable dragging of existing glyphs.
%%opts Path [width=400 height=400] (line_width=5 color='red') Polygons (fill_alpha=0.3) path = hv.Path([[(1, 5), (9, 5)]]) poly = hv.Polygons([[(2, 2), (5, 8), (8, 2)]]) path_stream = streams.PolyDraw(source=path, drag=True) poly_stream = streams.PolyDraw(source=poly, drag=True) path * poly
Whenever the data source is edited the data is synced with Python, both in the notebook and when deployed on the bokeh server. The data is made available as a dictionary of columns:
Alternatively we can use the
property to get an Element containing the returned data:
path_stream.element * poly_stream.element