-
-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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:
plotly-resampler/plotly_resampler/figure_resampler/figure_resampler_interface.py
Lines 413 to 416 in bb30c91
| # 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']}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working