Skip to content

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

Open
plotly/plotly.js
#7249
@joshlk

Description

@joshlk

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)

Activity

alexcjohnson

alexcjohnson commented on Oct 8, 2024

@alexcjohnson
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

joshlk commented on Oct 9, 2024

@joshlk
Author

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

alexcjohnson commented on Oct 9, 2024

@alexcjohnson
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 😎

joshlk

joshlk commented on Oct 24, 2024

@joshlk
Author

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

alexcjohnson commented on Oct 24, 2024

@alexcjohnson
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @gvwilson@alexcjohnson@joshlk

      Issue actions

        SI prefixes don't display Peta (P) correctly · Issue #4787 · plotly/plotly.py