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
hv.extension('bokeh')
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]
print(selected)
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
ds_dynamic = datashade(hv.DynamicMap(selected_info, streams=[selection]), x_sampling=.1, y_sampling=.1 )
ds_static + ds_dynamic
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:
Hello, were you able to fetch the lasso_select polygon to intersect that with the scatter plot of datashade for the dynamic map.
I am really new to holoviz and trying to do something similar, would appreciate your input
I should note that for large datasets this works best if spatialpandas is installed. I am leaning on holoviews 1.14.5 to make this work efficiently. I have not yet been able to have the link_selections on datashaded work coparable fast in holoviews 1.14.8 as in 1.14.5 using polygon or lasso_select.