A pure Julia implementation of state-of-the-art automatic regular and irregular histogram methods.
Most default histogram plotting software only support a few regular automatic histogram procedures and use very simple plug-in rules by default to compute the the number of bins, frequently leading to poor density estimates for non-normal data [cf. Birgé and Rozenholc (2006), Simensen et al. (2025)]. The purpose of this software package is to offer the user a fast and simple-to-use implementation of more sophisticated regular and irregular histogram procedures. Our package supports a variety of methods including those based on asymptotic risk minimization, leave-one-out cross-validiation, penalized maximum likelihood and fully Bayesian approaches.
Installing the package is most easily done via Julia's builtin package manager Pkg. This package is part of the Julia general registry, so the installation can be done via the two following lines of code:
using Pkg
Pkg.add("AutoHist")To get started, we illustrate the basic use of the package by fitting histograms to a normal random sample with an automatic selection of the histogram partition.
using AutoHist
x = randn(10^6)
h1 = fit(AutomaticHistogram, x)Several rules are available to select the histogram partition, and can be controlled through the use of the rule positional argument. For instance, a regular histogram based on maximizing the AIC can be fit as follows:
h2 = fit(AutomaticHistogram, x, AIC())Alternatively, we can use the autohist(x, rule; kwargs...) syntax, which serves as an alias for fit(AutomaticHistogram, x, rule; kwargs...). The code snippet below shows how to fit the AIC-based histogram using this method.
h2 = autohist(x, AIC())A detailed exposition of the keyword arguments passed to fit and autohist can be found by typing ?fit in the repl or in the API documentation. A detailed description of all methods currently implemented in AutoHist.jl can be found in the methods documentation.
The fitted histograms can be displayed through the Plots.jl or Makie.jl packages as follows:
import Plots, CairoMakie, Makie
Plots.plot(h1)
Makie.plot(h1)It is also possible to draw an automatic histogram by calling a supported plotting function directly:
Plots.histogram(x, AIC())
Makie.hist(x, AIC())For more details on the plotting capabilities offered by AutoHist.jl, see the plotting tutorial.
The argument rule determines the method used to construct the histogram for both of the histogram functions. The rule used to construct the histogram can be changed by setting rule equal to a symbol indicating the method to be used, e.g. BIC() which yields an automatic regular histogram based on the BIC criterion.
The default method is the Bayesian approach of Simensen et al. (2025), corresponding to keyword rule=RIH().
A detailed description of the supported methods can be found in the methods documentation.
If you encounter a bug when using this software or have a feature request, then feel free to open a github issue.
Coding contributions are also very much welcome, especially if you are looking to add a new automatic histogram method or a new algorithm for fitting an already-implemented bin selection rule. To make sure that your proposed new feature is a good fit for the AutoHist package, please open a new issue to discuss how your contribution could elevate AutoHist.jl.
If you find AutoHist.jl useful in your academic work, then please cite our JOSS paper using the following BibTeX entry:
@article{simensen2025autohist,
title={{AutoHist.jl: A Julia package for fast and automatic histogram
construction}},
author={Simensen, Oskar Høgberg},
journal={Journal of Open Source Software},
volume={10},
number={113},
pages={8850},
year={2025},
doi={10.21105/joss.08850}
}
Simensen, O. H., Christensen, D. & Hjort, N. L. (2025). Random Irregular Histograms. arXiv preprint. doi: 10.48550/ARXIV.2505.22034
Birgé, L., & Rozenholc, Y. (2006). How many bins should be put in a regular histogram. ESAIM: Probability and Statistics, 10, 24–45. doi: 10.1051/ps:2006001