-
-
Notifications
You must be signed in to change notification settings - Fork 74
Description
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.