Histogram does not scale to the range of new data on restyle
See original GitHub issueIf you set up a histogram…
var data1 = [1, 2, 2, 3, 3, 3, 4, 4, 5];
var hist = document.getElementById('hist_div');
Plotly.plot(hist, [{x: data1, type: 'histogram' }]);
… and then update this histogram with wider data followed by a restyle…
var data2 = [10, 20, 20, 30, 30, 30, 40, 40, 50];
Plotly.restyle(hist, {x: [data2]});
… the histogram keeps the old range (in this case 1 to 5) and does not scale to the range of the new data (which is the case when using scatter style plot). Here is a codepen showing this: http://codepen.io/rasmusab/pen/megKOo
I have not found any documentation regarding whether this is the expected behavior. If it is, what would be the best practice for updating a histogram with new data?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
A Complete Guide to Histograms | Tutorial by Chartio
Histograms are a common chart type used to look at distributions of numeric variables. Check out this guide to learn how to use...
Read more >Plotly histogram not rendering data correctly - Stack Overflow
I have a csv that I'm attemping to create a histogram of in plotly. The csv contains a date field (in hour increments),...
Read more >Making Histograms in R
At first glance, a histogram looks similar to a bar chart The most obvious difference is that in a histogram the rectangles of...
Read more >Visualization with Plotly.Express: Comprehensive guide
A detailed guide on how to create many visualizations with Plotly Express with layout styling, interactivity, animations, and many chart ...
Read more >Aggregations in Python - Plotly
... i in range(0, len(aggs)): agg = dict( args=['transforms[0].aggregations[0].func', aggs[i]], label=aggs[i], method='restyle' ) agg_func.append(agg) data ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ha, for colorscales it turns out we already do what I was about to propose here: if you explicitly specify
*auto: false
, then it will fill in the auto values but leave it looking like*auto: false
so that future changes will not re-invoke the autoscaling; but if you don’t specify an explicit*auto
value it defaults totrue
since the explicit ranges are missing.So for example:
and then:
range is still 1.5->2.5
But if you don’t specify
zauto: false
in the first place, the initial plot is identical but afterrestyle
you get: recalculated autocolor: 1->3So I think it’s only in the context of histogram bins that this is a change - and therefore I’d consider it an inconsistency, a bug, not a breaking change, and I should implement the same logic with explicit
autobin*: false
values in histograms.This means that if a user wants the auto first view (e.g. say the
cmin
andcmax
colorbar attribute) of the firstPlotly.newPlot
to remain after updates, they will need to setcmin
andcmax
to those value that they don’t know in advance, which is a little annoying in my mind.I’m not sure how common this use case is for plotly.js users. Maybe it doesn’t matter. Maybe we need another
auto
mode (e.g.cauto
would be an enumeratedtrue
,false
orfirst-view
). But at the very least I’d call what @alexcjohnson is proposing a breaking change.