Hello,
I am looking for a way to programmatically delete the LassoSelector from a FigureWidget.
Here is the reason :
I am using plotly (5.15.0) through jupyterlab (4.0.2) and I am struggling with LassoSelector.
I need to make interactive selections on two scatter plots where indexes selected in one plot should be reflected in the other plot.
I found a very usefull example here : Lasso deselect from inside a function - #2 by jmmease
import numpy as np
import plotly.graph_objs as go
import ipywidgets as widgets
from plotly.colors import DEFAULT_PLOTLY_COLORS
x = np.linspace(0,6,100)
y = np.sin(x)
data = [go.Scattergl(x=x, y=y, mode='markers', name = 'All nodes',
selected=dict(marker=dict(color=DEFAULT_PLOTLY_COLORS[1])))]
layout = dict(title=dict(text = 'plot1'), dragmode='lasso')
fig = go.FigureWidget(data=data, layout= layout)
data2 = [go.Scattergl(x=y, y=x, mode='markers', name = 'All nodes',
selected=dict(marker=dict(color=DEFAULT_PLOTLY_COLORS[1])))]
layout2 = dict(title=dict(text = 'plot2'), dragmode='lasso')
fig2 = go.FigureWidget(data=data2, layout= layout2)
def selection_fn(trace, points, selector):
fig2.data[0].selectedpoints = points.point_inds
def selection_fn2(trace, points, selector):
fig.data[0].selectedpoints = points.point_inds
fig.data[0].on_selection(selection_fn)
fig2.data[0].on_selection(selection_fn2)
display(widgets.HBox([fig,fig2]))
It is working well up to the moment we start to draw a selection on the other plot.
As the lasso is not deleted on the first plot, nothing happens when the selection is done on the second plot.
The only work around I found is to double click on the plot where I want to delete the lasso.
Is there a way to this programmatically (either emulating a double click or better lauching the same action that is launched to delete the lasso) ?
I guess it is what the originla author was doing using:
def selection_fn(trace, points, selector):
fig.data[0].selectedpoints = None
fig.data[0].selectedpoints = []
fig2.data[0].selectedpoints = points.point_inds
def selection_fn2(trace, points, selector):
fig2.data[0].selectedpoints = None
fig2.data[0].selectedpoints = []
fig.data[0].selectedpoints = points.point_inds
But this does not work (anymore ?).
Thank you very much in advance for you help !
Patrick