SI prefixes don't display Peta (P) correctly
Take this example whereby I set the exponentformat="SI" to use SI prefixes for the y-axis:
import plotly.express as px
import pandas as pd
import numpy as np
df = pd.DataFrame({'x': np.arange(1, 5), 'y': np.arange(1, 5)*1e12})
fig = px.line(
df,
x="x",
y="y",
)
fig.update_layout(
yaxis=dict(showexponent="all", exponentformat="SI"),
)
This correctly displays the y-axis using Tera (T) SI prefix units
If you increase the numbers so they are in the Peta (P) range:
df = pd.DataFrame({'x': np.arange(1, 5), 'y': np.arange(1, 5)*1e15})
fig = px.line(
df,
x="x",
y="y",
)
fig.update_layout(
yaxis=dict(showexponent="all", exponentformat="SI"),
)
It stops using SI prefixes on the y-axis and displays the numbers using x10^15:
Thanks @joshlk - I guess this is just a question of which prefixes we assume are well-enough known to include, as clearly at some point this needs to flip over to exponential notation. Tera is pretty common, and coincidentally matches the T in trillion. Peta we deemed to be less universally recognized, though in certain fields it and even Exa are in common use. Perhaps this could be made configureable in some way?
Hi @alexcjohnson, thanks for the reply. The SI prefixes are defined from q (10^-30) to Q (10^30), and different scientific fields will frequently use different ranges of these prefixes. For example, in computing, Peta FLOPS or Eta FLOPS measurements are common.
Also d3-format's formatPrefix function can display numbers in (mostly) the full SI unit range (10^-24 to 10^24). If we don't want Plotly to display the full SI range, could we add a comment to the documentation to make this explicit? Even better, could we just enable plotly to be able to use the full range of SI prefixes 🙂
Perhaps the simplest would be to add a new mode like SI extended that goes to +/- 24 or 30 before flipping to exponential? That’s probably pretty easy if you’d be interested in making a PR 😎
Hi, great. I am happy to make this contribution. Would it be possible to persuade you to extend the current SI format instead of making another? It seems like a more coherent solution as the documentation doesn't specify that it currently only displays SI units in the f (10^-15) to T (10^12) range. My expectation would be that if a user enables SI units then isn't it safe to assume that they won't mistake "P" to mean something other than Peta?
Looks like @dberardi99 beat you to it :tada: 🙇
I’d be happy to hear more opinions on this - seems to me though that since any solution we come up with MUST switch to exponential notation at some point, documenting where that happens is a separate concern from extending it. And to my mind making the full range standard carries too high a risk of making a graph that viewers can’t properly interpret, either because they don’t know as many of these prefixes as the graph creator or because new data has come in to an existing graph that extends its range.
I'd like to always use SI for larger/smaller numbers. For our use case we plot energy values at national level which is in the range of PJ (Peta Joules) or TWh (or Tera Watt hour). Our clients understand PJ, but not 10^15 J ... ;-)