Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI prefixes don't display Peta (P) correctly #4787

Open
joshlk opened this issue Oct 8, 2024 · 5 comments · May be fixed by plotly/plotly.js#7249
Open

SI prefixes don't display Peta (P) correctly #4787

joshlk opened this issue Oct 8, 2024 · 5 comments · May be fixed by plotly/plotly.js#7249
Labels
bug something broken P3 backlog

Comments

@joshlk
Copy link

joshlk commented Oct 8, 2024

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

newplot(1)

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:

newplot(2)

@alexcjohnson
Copy link
Collaborator

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?

@joshlk
Copy link
Author

joshlk commented Oct 9, 2024

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 🙂

@alexcjohnson
Copy link
Collaborator

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 😎

@gvwilson gvwilson added bug something broken P3 backlog labels Oct 10, 2024
@joshlk
Copy link
Author

joshlk commented Oct 24, 2024

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?

@alexcjohnson
Copy link
Collaborator

Looks like @dberardi99 beat you to it 🎉 🙇

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants