1

I am very new to Holoviews/DataShader/Bokeh, analyzing these libraries for a research project. I have a requirement to plot on 1 billion plots in a scatter plot and then on lasso of the plot capture the selected points , preferably the geometry of the selection.

I did come across the example -- http://holoviews.org/reference/streams/bokeh/Selection1D_points.html We need to link your selection stream to the holoviews element through a DynamicMap. Then, selection will hold your selected indices.

Below is what I have tried and have been successful in getting the geometry but the plot gets very slow and if its more and 1 million points I start getting browser memory issues and also the lasso is very very slow.

I have a dataframe with 3 columns x, y , pred
And this code gives me the plot
points = hv.Points(df)
datashaded = hd.datashade(points, aggregator=ds.count_cat('pred')).redim.range(x=(xmin, xmax), y=(ymin, ymax)).opts(
    width=600, height=600, tools=['box_select', 'lasso_select', 'hover'])

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


def lassocallback(geometry):
    if geometry is not None:
        with open('coordinates.txt', 'w') as f:
            np.savetxt(f, geometry)
    return points
# Final Plot

datashaded + hv.DynamicMap(lassocallback, streams=[lasso]).opts(width=600,height=600,tools=['box_select', 'lasso_select','hover'])

Also I get two plots as a result, as hv.DynamicMap alone won't show the points how do I just get a single plot for this.

  • HoloViews supports lasso selection on Datashader plots via a helper fuction called `link_selections`, and you can easily extract either the points or the shape of the selection. See http://holoviews.org/user_guide/Linked_Brushing.html, and if that lets you figure it out, please post the answer here as the solution, and if it doesn't, please post more details of what trouble you're having. (Or, if you want to start a. discussion, open a discourse question (https://discourse.holoviz.org/c/holoviews)). – James A. Bednar Mar 28 '21 at 16:30
  • I am trying to use Lasso from holoviews.streams and obtain the geometry of the selection on the datashaded plot. I do not need to link to plots, I just want to pick the geometry or the co-ordinates to do further processing. – Tasneem Talawalla Mar 28 '21 at 19:58
  • Sure. I don't know enough of the low-level implementation to help you with that, but I do know you can easily get it from link_selections. Maybe try it out with link_selections so that you can see how it's done (link_selections should work just fine with only a single plot, so it won't hurt anything to use it!), then re-implement it using the lower-level functionality involved. Or wait to see if someone who does know the lower-level tools chimes in! – James A. Bednar Mar 29 '21 at 14:45
  • @JamesA.Bednar - I updated my question a little, did find a way to obtain the geometry, but if the no of points increase the functionality gets impacted and at one point start getting browser memory issues, any pointers or advice? – Tasneem Talawalla Apr 01 '21 at 16:56
  • I don't often work with streams directly, but here I'd assume you don't want the source of the stream to be the points, because that's indeed going to be very slow, and for no reason, if you aren't also using it to extract the points. Seems like you'd want the source to be the datashaded object or even some dummy object with no points in it at all, just to get the shape of the lasso out. – James A. Bednar Apr 02 '21 at 20:45

0 Answers0