Hi
I have a usecase to plot a billion points in form of a datashaded scatter plot , and on lasso over the plot points, I need to select the geometry of the lasso, or somehow obtain the co-ordinates of it.
I have a pandas dataframe with three columns embed_x, embed_y and pred (this is a categorical value to define the color to the points)
#Below is my code
import numpy as np
import pandas as pd
embed_x= np.random.randn(1000)
embed_y= np.random.randn(1000)
pred=np.random.choice([1,2,3],size=1000,p=[.5,.25,.25])
df_from_arr = pd.DataFrame(data=[embed_x, embed_y,pred]).T
df_from_arr.rename(columns = {0:'embed_x',1:'embed_y',2:'pred'}, inplace = True)
df_from_arr.head()
xmin = df_from_arr['embed_x'].min()
xmax = df_from_arr['embed_x'].max()
ymin = df_from_arr['embed_y'].min()
ymax = df_from_arr['embed_y'].max()
from holoviews import opts
from holoviews import streams
import holoviews as hv
import holoviews.operation.datashader as hd
import datashader as ds
hv.extension("bokeh")
opts.defaults(opts.Points(tools=['box_select', 'lasso_select']))
# Declare some points
points_data = hv.Points(df_from_arr)
datashaded = hd.datashade(points_data,aggregator=ds.count_cat('pred')).redim.range(x=(xmin,xmax),y=(ymin,ymax))
# Declare points as source of selection stream
lasso = streams.Lasso(source=datashaded)
def lassocallback(geometry):
print(f"i am called {geometry}" )
return geometry
# Combine points and DynamicMap
datashaded + hv.DynamicMap(lassocallback, streams=[lasso]).opts(tools=['hover'])
But that does not seem to work, any help will be greatly appreciated.