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] Resample does not dynamically update for multiple xaxis #330

Open
clayton13 opened this issue Dec 25, 2024 · 0 comments
Open

[BUG] Resample does not dynamically update for multiple xaxis #330

clayton13 opened this issue Dec 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@clayton13
Copy link

Describe the bug 🖍️
When a go.Scattergl is created with an additional xaxis an exception is created and no dynamic updates occur. Looks similar to #322, where the self._grid_ref and self._xaxis_list do not appear to be set properly preventing updates beyond the initial xaxis.

Reproducing the bug 🔍

import plotly.graph_objects as go
import numpy as np
from plotly_resampler import FigureResampler

x = np.arange(1_000_000)
noisy_sin = (np.sin(x / 200) + np.random.randn(len(x)) / 10) * 1000

fig = FigureResampler(go.Figure())
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True),
              hf_x=x,
              hf_y=noisy_sin)
fig.add_trace(
    go.Scattergl(name='noisy sine 2', showlegend=True, xaxis='x2'),
    hf_x=x,
    hf_y=-1 * noisy_sin,
)
fig.update_layout(
    {'xaxis2': {
        'title': 'xaxis2 title',
        'overlaying': 'x',
        'side': 'top'
    }})
fig.show_dash(mode='inline')

Leading to a traceback:

...
  File "c:\Users\claytonwhite\ee_venv\lib\site-packages\plotly_resampler\figure_resampler\figure_resampler_interface.py", line 485, in _check_update_figure_dict
    trace_xaxis_filter: List[str] = layout_trace_mapping[layout_xaxis_filter]
KeyError: 'xaxis2'

Expected behavior 🔧
Expect both traces to update.

Environment information:

  • OS: Windows 10
  • Python environment:
    • Python version: Python 3.10.6
    • plotly-resampler environment: Dash web app, Chrome
  • plotly-resampler version: 0.10.0
  • plotly version: 5.24.1

Additional context
Hotfix (or rather hack) can be applied to dynamically populate for this case:

# edge case: an empty `go.Figure()` does not yet contain axes keys
if self._grid_ref is None:
return {"xaxis": ["x"]}

        if self._grid_ref is None:
            axis =  list(set([getattr(x, 'xaxis') or 'x' for x in self.data]))
            mappings = {}
            for ax in axis:
                val = list(map(int, re.findall(r'\d+', ax)))
                if val:
                    mappings[f'xaxis{val[0]}'] = [ax]
                else:
                    mappings[f'xaxis'] = ['x']
            return mappings # {'xaxis2': ['x2'], 'xaxis': ['x']}
@clayton13 clayton13 added the bug Something isn't working label Dec 25, 2024
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

No branches or pull requests

1 participant