Plotting a StatsBase.Histogram

Another particle physicist who likes step histograms here.
I’ve googled and came across this:
https://github.com/JuliaStats/StatsBase.jl/pull/243
I very much like the plots shown here, but this doesn’t seem to work (and I think this is unrelated to the fact that this pull request isn’t in a released version). Plots.jl does weird things when trying to plot a StatsBase.Histogram.
It also does weird things when doing things like histogram(randn(1000), bins=100, seriestype=:steps)

So my question is: What’s the recommended way to plot a StatsBase.Histogram?

There is a companion PR (https://github.com/JuliaPlots/Plots.jl/pull/713) on Plots that depends on this PR (EDIT in fact that PR was already merged onto the new_histogram branch). If you checkout the linked PR and the new_histogram branch in Plots it should work. It’d be cool if you could test it.
Until this gets merged, there is functionality in StatPlots to plot StatsBase.Histogram, but you won’t have the steps seriestype.

2 Likes

Checked out the JuliaPlots branch, and applied the pull request to StatsBase.
Non-uniform binning is no longer broken. (try, for example to histogram a normal distribution with the bins [-2.5, -2, -0.5, 0.1, 1.9, 2.5]. Using histogram, the bars overlap.
With the new version I can just do

plot(h)``` 
or 
`plot(h, seriestype=:steps)` and everything looks as expected.

That's as easy as it should be. Admittedly this is not a particularly thorough test, but I hope this gets merged soon.
2 Likes