Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] Resample does not dynamically update on zoom with subplots #322

Open
auxym opened this issue Oct 29, 2024 · 2 comments
Open

[BUG] Resample does not dynamically update on zoom with subplots #322

auxym opened this issue Oct 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@auxym
Copy link

auxym commented Oct 29, 2024

Describe the bug πŸ–οΈ
I believe this is similar to #242, which should be fixed. However I am using the latest plotly-resampler version installed by pip (0.10.0) and still experiencing the issue. #242 is also about multiple traces in a single plot (no subplots), this issue concerns specifically subplots.

When using subplots with the plotly.subplots.make_subplots function, when zooming in, only the first subplot gets dynamically resampled on zoom.

Reproducing the bug πŸ”
Here is a minimal code example, to be run in Jupyter:

import pandas as pd

import numpy as np

import plotly.graph_objects as go

from plotly.subplots import make_subplots

from plotly_resampler import register_plotly_resampler, unregister_plotly_resampler

register_plotly_resampler(mode="widget")

n = 2_000_000
x = np.arange(n)
x_time = pd.date_range("2020-01-01", freq="1s", periods=len(x))
noisy_sine = (3 + np.sin(x / 2000) + np.random.randn(n) / 10) * x / (n / 4)

fig = make_subplots(rows=2, cols=1)
fig.add_trace(go.Scatter(y=noisy_sine + 2, name="yp2"), row=1, col=1)
fig.add_trace(go.Scatter(y=noisy_sine - 3, name="ym1"), row=1, col=1)
fig.add_trace(go.Scatter(y=noisy_sine + 2, name="yp2"), row=2, col=1)
fig.add_trace(go.Scatter(y=noisy_sine - 3, name="ym1"), row=2, col=1)

print(type(fig))
display(fig)

Expected behavior πŸ”§
When zooming in on the first subplot (row=1), dynamic resampling works as expected. When zooming in on the second subplot, dynamic resampling does not work. I expected dynamic resampling to work the same on all subplots.

Environment information: (please complete the following information)

  • OS: Windows 11
  • Python environment:
    • Python version: 3.12
    • plotly-resampler environment: Jupyterlab on Firefox
  • plotly-resampler version: 0.10.0
@auxym auxym added the bug Something isn't working label Oct 29, 2024
@jonasvdd
Copy link
Member

jonasvdd commented Nov 6, 2024

Hi @auxym,

I am able to reproduce the bug. It appears to be related to the _xaxis_list property of the FigureWidgetResampler only picking up the first xaxis (and thus not subscribing on layout changes of the second axis).

As a quick and dirty fix, I would propose to just wrap the Figure object with a FigureWidgetResampler (before you output it).

...

fig.add_trace(go.Scatter(y=noisy_sine - 3, name="ym1"), row=2, col=1)

print(type(fig))
display(FigureWidgetResampler(fig))  # Wrap the Figure object

I hope to look further into this somewhere in the coming weeks!

@jonasvdd jonasvdd self-assigned this Nov 6, 2024
@auxym
Copy link
Author

auxym commented Nov 11, 2024

That workaround does work for now, thank you :)

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

No branches or pull requests

2 participants