predict-idlab / plotly-resampler

Visualize large time series data with plotly.py
https://predict-idlab.github.io/plotly-resampler/latest
MIT License
1.02k stars 66 forks source link

Refactor/remove trace updater #281

Closed jonasvdd closed 9 months ago

jonasvdd commented 10 months ago
[BUG] Patch does not seem to work with subplots
solved now!
Reproduce issue - clone this branch and run this code in a notebook. ```python from plotly_resampler import FigureResampler from plotly.subplots import make_subplots import plotly.graph_objects as go import numpy as np x = np.arange(2_000_000) noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000 fig = FigureResampler( make_subplots(rows=2, cols=2, shared_xaxes="columns", horizontal_spacing=0.03) ) log = noisy_sin * 0.9999995**x exp = noisy_sin * 1.000002**x fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=log) fig.add_trace(go.Scattergl(name="exp"), hf_x=x, hf_y=exp) fig.add_trace(go.Scattergl(name="-log"), hf_x=x, hf_y=-exp, row=1, col=2) fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=-log, row=2, col=1) fig.add_trace(go.Scattergl(name="3-exp"), hf_x=x, hf_y=3 - exp, row=2, col=1) fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=log**2, row=2, col=2) fig.show_dash(mode="inline") ``` Patch does not seem to properly work with subplots. How I use patch to update a figure with subplots: ```python patched_figure = dash.Patch() # create patch for trace in update_data[1:]: # skip first item as it contains the relayout trace_index = trace.pop("index") # the index of the corresponding trace # All the other items are the trace data which needs to be updated patched_figure["data"][trace_index] = trace # TODO -> how to make this work with subplots? return patched_figure ```

TODO:

codecov-commenter commented 9 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (9b48723) 96.46% compared to head (3570b01) 96.40%. Report is 1 commits behind head on main.

Files Patch % Lines
...tly_resampler/figure_resampler/figure_resampler.py 33.33% 2 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #281 +/- ## ========================================== - Coverage 96.46% 96.40% -0.06% ========================================== Files 14 14 Lines 1130 1140 +10 ========================================== + Hits 1090 1099 +9 - Misses 40 41 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jonasvdd commented 9 months ago

Ready for review @jvdd!