question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Histogram does not scale to the range of new data on restyle

See original GitHub issue

If 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:closed
  • Created 8 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alexcjohnsoncommented, Jul 20, 2017

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 to true since the explicit ranges are missing.

So for example:

var x1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4];
var y1 = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4];
Plotly.newPlot(gd, [{type: 'histogram2d', x: x1, y: y1, zauto: false}]);

screen shot 2017-07-20 at 12 35 48 pm

and then:

// move the last point so we have one bin that gets 1 sample, another gets 3
Plotly.restyle(gd,'x', [[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 3]])

screen shot 2017-07-20 at 12 37 17 pm 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 after restyle you get: screen shot 2017-07-20 at 12 38 56 pm recalculated autocolor: 1->3

So 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.

0reactions
etpinardcommented, Jul 20, 2017

I would actually argue that in all of these cases the update should reset the derived attributes

This means that if a user wants the auto first view (e.g. say the cmin and cmax colorbar attribute) of the first Plotly.newPlot to remain after updates, they will need to set cmin and cmax 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 enumerated true, false or first-view). But at the very least I’d call what @alexcjohnson is proposing a breaking change.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found