plotly / plotly/plotly.js

enable formatting numbers with natural language suffixes, k(ilo), M(illion), B(illion)

Aperta
#6,091 3 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Plotly doesn't currently let me format numbers, e.g. in hover templates, in "human" or "business" form, by which I mean essentially SI representation but with the suffix replacements k->k(ilo) M->M(illion), G->B(illion), T->T(trillion),.... (by pure luck, this is really just one necessary replacement in the range I've listed).

The reason seems to be that plotly relies on d3-format, which claims to "format numbers for human consumption" but misses the one format non-technically trained humans can actually consume at ease.

However, oddly plotly does use the "human readable" form by default for the X and Y columns in default hover displays, even when they're included in the hover templates manually as %{y}, but not for custom data included via %{customdata[0]} (see the MWE below). This in some sense makes this a bug: You want to include two columns of data in the same way, using the same format specifier, but you get different results.

Instead of waiting on d3, I would like to make this feature request: I believe plotly should default for custom data to the same formatting it uses by default elsewhere (including axes labels), unless a format specifier is explicitly listed, thus increasing consistency.

Example: Despite using text=y and hovertemplate ='%{y}<br>%{text}', I get different representations:

import plotly.graph_objects as go
y = [2, 100000, 2000000, 2000000000]
fig = go.Figure(go.Scatter(
    x = [1,2,3,4],
    y = y,
    text = y,
    hovertemplate ='%{y}<br>%{text}'
))
fig.show()

image

Similar requests elsewhere:
https://github.com/plotly/plotly.py/issues/1222

https://stackoverflow.com/questions/68005050/b-billions-instead-of-g-giga-in-python-plotly-customdata-si-prefix-d3

https://stackoverflow.com/questions/17037023/how-to-get-localizable-or-customizable-si-codes-with-d3-format

https://community.plotly.com/t/custom-si-unit-prefixes/29739/4

https://stackoverflow.com/questions/40774677/d3-formatting-tick-value-to-show-b-billion-instead-of-g-giga

https://github.com/d3/d3/issues/2241

https://stackoverflow.com/questions/64313173/how-to-hover-number-formatting-to-k-or-m-accordingly-in-r-plotly-pie-charts-and

https://github.com/d3/d3-format/issues/71

https://github.com/d3/d3-format/pull/81

https://github.com/d3/d3-format/pull/96

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 tracciando il modo in cui vengono formattati i valori di hovertemplate, in particolare %{y}, %{text} e %{customdata[0]}, e come viene utilizzato d3-format per gli assi e gli hover predefiniti. Confronta il comportamento esistente con l’esempio, quindi definisci test che dimostrino che i dati personalizzati seguono la formattazione predefinita, a meno che non venga fornito uno specificatore di formato esplicito, inclusi i suffissi richiesti in linguaggio naturale.

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

Valutazione

Stack tecnologico
d3, javascript
Ambito
data-visualization
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.