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 · 0 comments · May be fixed by #336
Open

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

yzhaoinuw opened this issue Feb 9, 2025 · 0 comments · May be fixed by #336
Assignees
Labels
bug Something isn't working

Comments

@yzhaoinuw
Copy link

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
@yzhaoinuw yzhaoinuw linked a pull request Feb 9, 2025 that will close this issue
@jonasvdd jonasvdd self-assigned this Feb 11, 2025
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