-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Reproducible example
Demo: https://codepen.io/Lexachoc/pen/KwdWZGv
The problem
When the histogram data changes (mutates) and layout.barmode
is set to 'overlay'
, the bin size resets to 1.
This happens in two cases:
- Switching from linear (numeric) values to category values, then back to linear.
category values (after changing data):
After:
linear (numeric) (after changing back):
- Switching from linear (numeric) values to linear (numeric), then back to original data.
linear (numeric) (after changing data):
After:
linear (numeric) (after changing back):
You can clearly see the bins become extremely thin after the data update, but only when barmode: 'overlay'
is used.
Expected behavior
Bin sizes should remain consistent or auto-adjust correctly when data changes, not reset to 1, which makes the bins extremely thin.
Why this is important
For react-plotly
and other reactive setups, data changes are very common. This bug makes histogram rendering unreliable when using 'overlay'
, which is often needed for comparing multiple datasets. It is a critical issue for apps that frequently re-render histograms with updated data.
This problem seems to exist for many years. I've seen similar issues reported a long time ago.
Relevent issue
Note
This issue may just be a side effect of Plotly.react
(see #2389) that happens to be visible in this case. Here, I'm only focusing on the resulting bin size issue.