Hi there,
I am trying to use the lasso to select data on one plot and show in in the other plot via indices and vice versa, however I cannot make it work since the data of the first plot stays selected. Does anyone know how to call a lasso (or range) deselect from a function?
here an attemp to make it work:
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]))),
go.Scattergl(mode='markers', name='selected nodes')]
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]))),
go.Scattergl(mode='markers', name='selected nodes')]
layout2 = dict(title=dict(text = 'plot2'), dragmode='lasso')
fig2 = go.FigureWidget(data=data2, layout= layout2)
def selection_fn(trace, points, selector):
# !!!! here call deselect lasso from plot2
fig.data[1].x = [None]
fig.data[1].y = [None]
fig.layout.xaxis.autorange = True
fig2.data[1].x = y[points.point_inds]
fig2.data[1].y = x[points.point_inds]
def selection_fn2(trace, points, selector):
# !!!! here call deselect lasso from plot1
fig2.data[1].x = [None]
fig2.data[1].y = [None]
fig.data[1].x = x[points.point_inds]
fig.data[1].y = y[points.point_inds]
fig.data[0].on_selection(selection_fn)
fig2.data[0].on_selection(selection_fn2)
display(widgets.HBox([fig,fig2]))
I made this as an alternative but it was not really what i aimed to do:
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', marker=dict(color=np.array([DEFAULT_PLOTLY_COLORS[0]]*len(x))),
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', marker=dict(color=np.array([DEFAULT_PLOTLY_COLORS[0]]*len(x))),
selected=dict(marker=dict(color=DEFAULT_PLOTLY_COLORS[2])))]
layout2 = dict(title=dict(text = 'plot2'), dragmode='lasso')
fig2 = go.FigureWidget(data=data2, layout= layout2)
def selection_fn(trace, points, selector):
col = np.array([DEFAULT_PLOTLY_COLORS[0]]*len(x))
col[points.point_inds] = np.array([DEFAULT_PLOTLY_COLORS[1]]*len(points.point_inds))
fig2.data[0].marker.color = col
def selection_fn2(trace, points, selector):
col = np.array([DEFAULT_PLOTLY_COLORS[0]]*len(x))
col[points.point_inds] = np.array([DEFAULT_PLOTLY_COLORS[2]]*len(points.point_inds))
fig.data[0].marker.color = col
fig.data[0].on_selection(selection_fn)
fig2.data[0].on_selection(selection_fn2)
display(widgets.HBox([fig,fig2]))