plotly / plotly/plotly.py

go.Scatter ignores the masked array elements in numpy masked arrays

Aperta
#4,213 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

Bug summary

Plotting a numpy masked array, px.scatter plots the non-masked array elements and limits the axis accordingly, while go.Scatter also displays the masked data and does also include the masked elements for the axis limits. The behavior from go.Scatter is unexpected in this regard and ignoring the mask defeats the purpose of masked arrays.

Minimal viable code

import numpy.ma as ma
import plotly.express as px
import plotly.graph_objects as go

# Create timestamps
time_unmasked = [1,2,3,4,5,6,7]

# Create a masked array with three masked variables, one datapoint far from others
data_masked = ma.array([15,14,50,15,15,15,16], mask=[0,0,1,1,1,0,0])

fig_px = px.scatter(x=time_unmasked, y=data_masked, title='Plotly Express')
fig_px.show()

fig_go = go.Figure(layout=go.Layout(
        title=go.layout.Title(text="Plotly Graph Objects")))
fig_go.add_trace(go.Scatter(x=time_unmasked, y=data_masked))
fig_go.show()

Thanks to @Benblob688 for his code example in the issue mentioned below.

Actual outcome
newplot
Using plotly.graph_objects, the masked data entries at position 2,3,4 with the values 50,15,15 are drawn into the plot and the axis limits are set accordingly.
Expected outcome
newplot (1)
Using plotly.express, the masked data entries are not shown and the axis limits are set accordingly to only include non-masked entries in the array.

Additional information
Matplotlib had a similar issue here, where the code has been adapted from to display this issue here. It seems that the usage of np.column_stack caused an issue there, that function has since been replaced with np.ma.column_stack.

Operating system

Ubuntu 20.04

Plotly Version

5.14.1
Numpy Version
1.24.1
Python version

3.11.3
Installation

conda

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

Inizia con l’esempio di codice minimo e confronta px.scatter con go.Scatter quando viene fornito l’array NumPy mascherato. Traccia il modo in cui ciascun punto di ingresso gestisce gli elementi mascherati e i limiti degli assi, quindi aggiungi o aggiorna la copertura per l’esempio segnalato. Il lavoro è completato quando go.Scatter non disegna più i valori mascherati e non li include più nei limiti degli assi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
numpy, 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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.