plotly / plotly/plotly.py

On_selection event in faceted plot only works correctly in first facet

Aperta
#4,423 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
Python
Stelle
18.8k
Fork
2.8k
Merge medio
16h 26m
PR unite (30g)
21

Descrizione

Hello,
I’m trying to catch on_selection events in a faceted figure.

I create a simple faceted figure, and attach an on_selection handler to all traces.
As an output, I simply print the customdata, and the selector.xrange.

When selecting an area in the first facet, the selector.xrange is an array of numbers, the customdata corresponds to the data for the left facet.
However, when I do the same in the second facet, the selector.xrange becomes an , and the customdata still appears to be coming from the left facet.

I expect the selector.xrange to also be an array of numbers, when selecting in the right facet.

Here are the sample code (to be executed in jupyter notebook) and a screenshot of the result.

py.init_notebook_mode()

df = pd.DataFrame({
    "x": [1,2,3,4,1,2,3,4],
    "y": [1,2,3,2,1,4,2,3],
    "side": ["left","left","left","left","right","right","right","right"],
    "customdata": [1,2,3,4,5,6,7,8]
})

fig = px.line(df, x="x", y="y", custom_data=["side","customdata"], facet_col="side")

# fig.update_layout(clickmode='event+select')
fig.update_layout(
            dragmode="select",
            clickmode="select"
        )
fig.update_traces(marker_size=20)

f = go.FigureWidget(fig)

def click_handler(trace, points, selector):
    print(trace.customdata)
    print(selector.xrange)
    
f.data[0].on_selection(click_handler)

f

image

Kind Regards

Bart

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui l'esempio di faceted-plot fornito in un notebook Jupyter e ispeziona il callback di selezione di FigureWidget collegato tramite f.data[0].on_selection. Confronta selector.xrange e trace.customdata quando selezioni le facette sinistra e destra. Il lavoro è completato quando le selezioni in entrambe le facette riportano l'intervallo numerico e i dati della facetta appropriati.

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à
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.