Box/Lasso selection giving wrong indices in point_inds for px.scatter
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 18.8k
- Fork
- 2.8k
- Merge medio
- 16h 26m
- PR unite (30g)
- 21
Descrizione
Hi,
I am implementing lasso/box selection in a scatterplot. I am using a callback function that returns me the indices of data selected by the user. The code works fine and returns me the correct indices when I applied a continuous or no label to the points. However, when I color the points using a discrete label I get incorrect indices or empty array.
Sample code to run is given below.
import plotly.express as px
import plotly.graph_objects as go
from plotly.graph_objs import *
from IPython.display import display
df = px.data.iris()
selected = []
def filter_(trace, points, state):
global selected
print(points)
selected = points.point_inds
layout = Layout(
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
width=1000,
height=600,
)
fig = px.scatter(
df,
x='sepal_length',
y='sepal_width',
color="species",
)
fig.layout=layout
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)
fig = go.FigureWidget(fig.data, fig.layout)
fig.layout.dragmode = 'lasso'
fig.data[0].on_selection(filter_)
display(fig)
dh = display(display_id=True)
On making a lasso/box selection this is the output thrown. As you can see point_inds is empty.
Points(point_inds=[],
xs=[],
ys=[],
trace_name='setosa',
trace_index=0)
If you comment color="species" , the code works fine.
In the above code, I also applied on_selection on all objects of fig.data but still did not work.
for f in fig.data:
f.on_selection(filter_)
Version info -
Python - '3.8.8'
Plotly - '5.11.0'
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l'esempio fornito con px.scatter e FigureWidget in un notebook Jupyter usando Python 3.8.8 e Plotly 5.11.0, confrontando la selezione con e senza color="species". Traccia i callback di selezione su fig.data e verifica che point_inds contenga le righe selezionate per ogni trace colorato; il lavoro è completato quando la selezione lasso e quella a riquadro riportano gli indici attesi invece di un array vuoto o errato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- jupyter-notebook, python
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100