Skip to content

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

Open
@yzhaoinuw

Description

@yzhaoinuw

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions