plotly / plotly/plotly.js

unexpected histogram bin size behavior

Aperta
#6,556 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
JavaScript
Stelle
18.3k
Fork
2k
Merge medio
2g 12h
PR unite (30g)
28

Descrizione

If the maximum number in the interval is a multiple of the bin size, then this number is lost.
Here is a code example:

var x = [1.0, 9.1, 10.0, 17.8, 18.5, 20.0];

var trace = {
    x: x,
    type: 'histogram',
    autobinx: false,
    xbins: { 
      end: 20.0, 
      size: 10.0,
      start: 0
    }
};
var data = [trace];
Plotly.newPlot('myDiv', data);

Screenshot from 2023-04-07 17-22-43

This is the result of using the notation [a; b) when creating groups. This behavior creates a problem, for example, when you want to dynamically adjust the bin size depending on the step. Here is an example:

var data = [1.0, 9.1, 10.0, 17.8, 18.5, 20.0];

step = 1.0; // any value from the interval: [0; 1]

xbins_start = data.reduce((x, y) => Math.min(x, y), 0.0);
xbins_end   = data.reduce((x, y) => Math.max(x, y), 0.0);
xbins_size  = (step * (xbins_end - xbins_start));

var trace = {
    x: data,
    type: 'histogram',
    autobinx: false,
    xbins: { 
      start: xbins_start,
      end: xbins_end,
      size: xbins_size
    }
};

Plotly.newPlot('myDiv', [trace]);

By setting the step size to 1, I hope to get the only one group containing all the data values (the height of the bin should be 6), instead I get a height of 5 with the loss of the maximum value.

Screenshot from 2023-04-07 17-04-13

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 la riproduzione JavaScript nell’issue e segui il percorso di binning dell’istogramma per i valori espliciti start, end e size di xbins. Verifica il comportamento ai limiti con i dati forniti e conferma che un valore uguale a end venga conteggiato nel bin risultante.

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

Valutazione

Stack tecnologico
javascript
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.