Merge pull request #707 from mkborregaard/new-histogram

fix uneven bins
This commit is contained in:
Michael Krabbe Borregaard 2017-02-26 08:33:30 +01:00 committed by GitHub
commit 34c0361d1a

View File

@ -410,6 +410,8 @@ function my_hist(v, bins; normed = false, weights = nothing)
counts[idx] += (weights == nothing ? 1.0 : weights[i]) counts[idx] += (weights == nothing ? 1.0 : weights[i])
end end
counts = isapprox(extrema(diff(edges))...) ? counts : counts ./ diff(edges) # for uneven bins, normalize to area.
# normalize by bar area? # normalize by bar area?
norm_denom = normed ? sum(diff(edges) .* counts) : 1.0 norm_denom = normed ? sum(diff(edges) .* counts) : 1.0
if norm_denom == 0 if norm_denom == 0
@ -424,7 +426,8 @@ end
edges, counts = my_hist(y, d[:bins], edges, counts = my_hist(y, d[:bins],
normed = d[:normalize], normed = d[:normalize],
weights = d[:weights]) weights = d[:weights])
x := edges bar_width := diff(edges)
x := centers(edges)
y := counts y := counts
seriestype := :bar seriestype := :bar
() ()