Closed heron1 closed 1 year ago
This problem is probably due to Plotly.js since it uses default bins here (because you didn't specify them, apart from the number):
This is a part of the JavaScript generated in the Browser window – as you can see, only nbinsx
is specified.
I don't know why Plotly.js uses -0.1 as lower and 1.1 as upper limit when values range from 0 to 1 but this is the source of the problem.
So, try this:
let xBins = TraceObjects.Bins.init(Start = 0., End = 1., Size = 0.2)
let histo2 = Chart.Histogram(X = x, NBinsX = 5, XBins = xBins)
histo2 |> Chart.show
This solves the problem:
And it can also be seen when inspecting the page source's JS code:
Thanks! That seems to do the trick. It also seems the NBinsX parameter is no longer necessary.
@heron1 can we close this or do you still have issues with histogram bin sizes?
hi yes it can be closed thanks
Description
Chart.Histogram seems to not accurately reflect the underlying data, unless I'm misunderstanding how things work.
Repro steps
This shows a histogram chart with a non-even distribution of what should be evenly distributed numbers (5 bins, each 0.2 in size, from 0 to 1). In fact, bin 0-0.2, and bin 0.8-1 show only 100k elements, whilst bins 0.2-0.4, 0.4-0.6, 0.6-0.8 show 200k elements - a 50% error.
Expected behavior
There should be an even distribution. This can be confirmed by running the following code after the above code:
(the counts are evenly distributed)
Related information