plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Y-axis tickformat='+' causes unexpected scientific notation for zero tick

Open JohnorJohnny opened this issue 8 months ago • 1 comments

Hi Plotly team,

I'm encountering an issue when trying to display the sign for all Y-axis tick labels using the tickformat='+' format. Specifically, when the Y-axis includes a tick near zero, Plotly displays it in scientific notation instead of as +.

Problem

Setting tickformat='+' on the Y-axis leads to unexpected tick labels like -8.881784197e-17, which appears instead of a clean +0. This seems to be due to floating-point precision errors, but it's surprising that it breaks the format hint and drops into scientific notation.

Minimal reproducible example

import plotly.graph_objects as go

figure = go.Figure()

figure.add_scatter(
    x=[1],
    y=[0.58],
)

figure.update_layout(
    yaxis={
        'range': [-0.66, 0.66],
        'tickformat': '+',
    },
)

figure.show()
Image

Expected Behavior

All tick labels on the Y-axis should respect the + format and include a sign, including zero. The tick at (or near) zero should be displayed as +0, not in scientific notation.

Thanks for the awesome work on Plotly!

JohnorJohnny avatar Apr 24 '25 16:04 JohnorJohnny

I'm sure Plotly will address this formatting issue soon. Meanwhile, you can use this alternative method:

import plotly.graph_objects as go

figure = go.Figure()

figure.add_scatter( x=[1], y=[0.58], )

figure.update_layout( yaxis=dict( range=[-0.66, 0.66], tickmode='array', tickvals=[-0.66, 0, 0.66], ticktext=['-0.66', '+0', '+0.66'], ), )

figure.show()

Image

rahimbaig28 avatar May 22 '25 13:05 rahimbaig28