Selection1D Points#

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


Title: Point Selection1D stream example#

Description: A linked streams example demonstrating how to use Selection1D to get currently selected points and dynamically compute statistics of selection.

Dependencies: Bokeh

Backends: Bokeh, Plotly

import numpy as np
import holoviews as hv
from holoviews import opts
from holoviews import streams
hv.extension('bokeh')
opts.defaults(opts.Points(tools=['box_select', 'lasso_select']))

# Declare some points
points = hv.Points(np.random.randn(1000,2 ))

# Declare points as source of selection stream
selection = streams.Selection1D(source=points)

# Write function that uses the selection indices to slice points and compute stats
def selected_info(index):
    selected = points.iloc[index]
    if index:
        label = 'Mean x, y: %.3f, %.3f' % tuple(selected.array().mean(axis=0))
    else:
        label = 'No selection'
    return selected.relabel(label).opts(color='red')

# Combine points and DynamicMap
points + hv.DynamicMap(selected_info, streams=[selection])
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).