CurveEdit#

Download this notebook from GitHub (right-click to download).


Title: CurveEdit Stream#

Description: A linked streams example demonstrating how to use the CurveEdit stream.

Dependencies: Bokeh

Backends: Bokeh

import numpy as np
import holoviews as hv

from holoviews import opts, streams
from holoviews.plotting.links import DataLink

hv.extension('bokeh')

The CurveEdit stream adds a bokeh tool to the source plot, which allows drawing, dragging and deleting points and making the drawn data available to Python. The tool supports the following actions:

Move vertex

Tap and drag an existing vertex, the vertex will be dropped once you let go of the mouse button.

Delete vertex

Tap a vertex to select it then press BACKSPACE or DELETE key while the mouse is within the plot area.

As a simple example we will create a CurveEdit stream and attach it to a Curve with a simple timeseries. By using a DataLink we then link the tool to a Table.

If we select the PointDraw tool () the vertices will appear and allow us to drag and delete vertex. We can also see the x/y position change in the table and edit it. To change the appearance of the vertices we can supply a style to the CurveEdit stream:

curve = hv.Curve(np.random.randn(10).cumsum())

curve_stream = streams.CurveEdit(data=curve.columns(), source=curve, style={'color': 'black', 'size': 10})

table = hv.Table(curve).opts(editable=True)
DataLink(curve, table)

(curve + table).opts(
    opts.Table(editable=True))

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:

curve_stream.data
{'x': [np.float64(0.0),
  np.float64(1.0),
  np.float64(2.0),
  np.float64(3.0),
  np.float64(4.0),
  np.float64(5.0),
  np.float64(6.0),
  np.float64(7.0),
  np.float64(8.0),
  np.float64(9.0)],
 'y': [np.float64(-1.0889933027200847),
  np.float64(-0.37220160494354493),
  np.float64(0.3670651035076784),
  np.float64(1.1116496468155483),
  np.float64(0.648331678450452),
  np.float64(-0.06681695605279814),
  np.float64(0.7208684073114217),
  np.float64(1.8465381547926891),
  np.float64(2.5108614861021827),
  np.float64(3.645522164883389)]}

Alternatively we can use the element property to get an Element containing the returned data:

curve_stream.element
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).