- A linked streams example demonstrating how to use the BoxDraw stream.
- streams, linked, position, interactive
import numpy as np import holoviews as hv from holoviews import streams hv.extension('bokeh')
stream adds a bokeh tool to the source plot, which allows drawing, dragging and deleting boxes and making the drawn data available to Python. The tool supports the following actions:
Hold shift then click and drag anywhere on the plot.
Click and drag an existing box, the box will be dropped once you let go of the mouse button.
Tap a box to select it then press BACKSPACE key while the mouse is within the plot area.
As a very straightforward example we will create a Polygons element containing multiple boxes, then attach it as a source to a
stream instance. When we now plot the
Polygons instance it will add the tool, letting us draw, drag and delete the box polygons:
%%opts Polygons [width=400 height=400 default_tools=] (fill_alpha=0.5) boxes = hv.Polygons([hv.Box(0, 0, 1), hv.Box(2, 1, 1.5), hv.Box(0.5, 1.5, 1)]) box_stream = streams.BoxEdit(source=boxes) boxes
Whenever an action is executed the geometry data will be synced with Python, both in the notebook and when deployed on the bokeh server. We can access the data directly as columns of the corners of each box:
Alternatively we can use the
property to get an Element containing the returned data: