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

px.line erratic and wrong for large x value ranges #4655

Open
eisenlohr opened this issue Jul 5, 2024 · 0 comments
Open

px.line erratic and wrong for large x value ranges #4655

eisenlohr opened this issue Jul 5, 2024 · 0 comments
Labels
bug something broken P3 not needed for current cycle

Comments

@eisenlohr
Copy link

eisenlohr commented Jul 5, 2024

Problem

Plotting a straight line from ($-X$, 0) to ($+X$, 1) for various (large) $X$ within a much smaller window results in wrong and inconsistent behavior, as demonstrated in below minimum non-working examples (using a Jupyter notebook with plotly.js v2.27.0).

I doubt that this behavior can be explained by intrinsic rounding problems, since

>>> np.interp([-0.1,0.1],[-1e17,+1e17],[0,1])
array([0.5, 0.5])

>>> np.interp([-0.1,0.1],[-1e18,+1e18],[0,1])
array([0.5, 0.5])

Examples

Data frame

df = pd.DataFrame(dict(x=[-1e17,+1e17,-1e18,+1e18],
                       y=[0,1,0,1],
                       xlimit=['±1e17','±1e17','±1e18','±1e18']))

Very tight plotting range (symmetric 0.1)

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-.1,.1],
              range_y=[0.4,0.6],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

pxLine_0_1

Slightly wider plotting range (symmetric 0.3)

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-.3,.3],
              range_y=[0.4,0.6],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

pxLine_0_3

Another plotting range (symmetric 1)

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-1,1],
              range_y=[0.4,0.6],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

pxLine_1

Another even wider plotting range (symmetric 3)

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-3,3],
              range_y=[0.4,0.6],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

pxLine_3

Apparently wide enough plotting range (symmetric 3.2)

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-3.2,3.2],
              range_y=[0.4,0.6],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

pxLine_3_2

As far as my tests go, for any range_x that is wider than about ±3, the plotting is rendered correctly:

fig = px.line(df,x='x',y='y',color='xlimit',
              range_x=[-1e17,1e17],
              range_y=[0,1],
              width=400,
              height=400,)
fig.update_traces(opacity=0.5)
fig.show()

px_Line_full

@gvwilson gvwilson self-assigned this Jul 12, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P3 not needed for current cycle bug something broken labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 not needed for current cycle
Projects
None yet
Development

No branches or pull requests

2 participants