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

[BUG]Resetting Axes Doesn't Reset Trace If X-Axis Range Is Set #335

Open
yzhaoinuw opened this issue Feb 9, 2025 · 3 comments
Open

[BUG]Resetting Axes Doesn't Reset Trace If X-Axis Range Is Set #335

yzhaoinuw opened this issue Feb 9, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@yzhaoinuw
Copy link
Contributor

Bug Description 🖍️

In a FigureResampler, if the x range of a subplot is set and if the number of points in the subplot exceeds default_n_shown_samples, then clicking Reset Axes after zooming in on the subplot does not reset the trace. It still shows the trace in the zoomed-in view while the x range of the subplot is reset. The user needs to pan or zoom in or out on the subplot again to reset the trace.

Reproducing The Bug 🔍

Minimal code to reproduce the bug.

import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly_resampler import FigureResampler


time = 1000
N = 4001 # number of points in the subplot exceeds default_n_shown_samples
x = np.linspace(0.0, time, N, endpoint=False)
y = np.cos(1/2 * np.pi + 2 / 50 * np.pi * x)

fig = FigureResampler(
    make_subplots(
        rows=1,
        cols=1,
    ),
    default_n_shown_samples=4000,
)

fig.add_trace(
    go.Scattergl(
        line=dict(width=1),
        marker=dict(size=2, color="blue"),
        showlegend=False,
        mode="lines+markers",
    ),
    hf_x=x,
    hf_y=y,
    row=1,
    col=1,
)

fig.update_xaxes(
    range=[0, np.ceil(x[-1])], # set the x range of the subplot
    row=1,
    col=1,
)

fig.show_dash(config={"scrollZoom": True})

Expected Behavior 🔧

When clicking Reset Axes after zooming in, the trace should be reset along with the x-axis.

Screenshots 📸

plotly_bug_demo.mp4

Environment Information

  • OS: Windows 11
  • Python environment:
    • Python version: 3.12.8
    • plotly-resampler environment: Web Dash App, Chrome
  • plotly-resampler version: 0.10.0

Possible Cause

I noticed that in the situation described above, after clicking Reset Axes, relayoutdata only has xaxis.range, but not xaxis.range[0] and xaxis.range[1]. This seemed to be the cause of the bug because in the function _construct_update_data, it explicitly matches the start and the end in thr format of xaxis\d*.range\[0] and xaxis\d*.range\[1], respectively, in order to update the trace.

@yzhaoinuw yzhaoinuw added the bug Something isn't working label Feb 9, 2025
yzhaoinuw added a commit to yzhaoinuw/plotly-resampler that referenced this issue Feb 9, 2025
@jonasvdd jonasvdd self-assigned this Feb 11, 2025
@yzhaoinuw
Copy link
Contributor Author

Hello @jonasvdd, how are you? Does my issue make sense and is it reproducible? Would my fix work?
I had trouble passing the checks and wasn't sure what to do. Do you have any suggestions? Would love to contribute to your awesome library!

@jonasvdd
Copy link
Member

jonasvdd commented Mar 4, 2025

Hi @yzhaoinuw,

I was occupied with some other code development! I will have a look at it somewhere later this week!
Keep you posted! 😄

jonasvdd pushed a commit to jonasvdd/plotly-resampler that referenced this issue Mar 6, 2025
jonasvdd added a commit that referenced this issue Mar 6, 2025
* Fix: Add xaxis.range[0]/[1] If Not Exist #335

* 🔍 adding test + some more docs

---------

Co-authored-by: yzhaoinuw <[email protected]>
@jonasvdd
Copy link
Member

jonasvdd commented Mar 6, 2025

Fixed in #342, will be included in a new release!
Thank you for pointing out this issue and the qualitative fix 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants