Link datashade lasso_select to dmap stream

I have a large dataset that I want datashade and then datashade a subset based on the lasso_select. This is very similar to an example at

except that I want to lasso_select from a datashaded scatter plot.
I would be interested in finding a way to fetch the lasso_select polygon to intersect that with the scatte upfron of datashade for hte dynamic map.

import numpy as np
import holoviews as hv
from holoviews import opts
from holoviews import streams
from holoviews.operation.datashader import datashade

opts.defaults(opts.Scatter(tools=['box_select', 'lasso_select']))

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

ds_static = datashade(points).opts(tools=['box_select', 'lasso_select'], active_tools=['box_select'])

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

# 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))
        label = 'No selection'
    return selected.relabel(label).opts(color='red')

# Combine points and DynamicMap

ds_dynamic = datashade(hv.DynamicMap(selected_info, streams=[selection]), x_sampling=.1, y_sampling=.1 )
ds_static + ds_dynamic

Any suggestions please?

I only just merged a PR which supports accessing the lasso select polygon from Python, it will be released in HoloViews 1.13.3. Note also that linked brushing will do all the hard work for you, e.g. the example can basically be rewritten as:

points = hv.Scatter(np.random.randn(10000,2 ))

def selected_info(points):
    label = 'Mean x, y: %.3f, %.3f' % tuple(points.array().mean(axis=0))
    return points.relabel(label)

selected = points.apply(selected_info)

Thank you for quick reply, this sounds great! Any chance to be able to do this to some extent in holoviews version 1.12.7?