Hist
Hist is an analyst-friendly front-end for boost-histogram, providing enhanced classes and utilities for histogramming in Python. It offers features like named axes, quick construction shortcuts, and integrated plotting capabilities, building on the performance of boost-histogram. The library is actively maintained, with its current version being 2.10.1, and typically releases updates to align with Python and boost-histogram version changes.
Warnings
- breaking Support for older Python versions is periodically dropped. As of v2.10.0, Python 3.9 is no longer supported. v2.9.0 dropped Python 3.8, and v2.8.0 dropped Python 3.7. The library requires Python 3.10+.
- breaking The minimum required version of `boost-histogram` has increased. For example, v2.10.0 dropped support for `boost-histogram` 1.5, requiring 1.7.0 or later. Earlier versions also saw similar increases.
- deprecated The `[plot]` extra was split, with some functionalities moving to a new `[fit]` extra. If you previously installed with `[plot]` and relied on fitting tools, you might need to adjust your installation.
- gotcha When working with Dask-backed histograms (e.g., `hist.dask.Hist`), the histogram object represents a computation graph. The actual histogram data is only materialized when `.compute()` is explicitly called on the object or a dask `compute()` function is used.
- gotcha Using named axes is highly recommended as it enables more powerful indexing and manipulation shortcuts. While unnamed axes are allowed, many advanced features and syntactic sugars are designed around named axes. The `NamedHist` class forces names to be used in most places.
- gotcha If filling an unweighted storage with weights, `hist.variances()` will return `None` as variances cannot be correctly computed. This can lead to unexpected behavior if you rely on variance calculations.
Install
-
pip install hist -
pip install "hist[plot,fit,dask]"
Imports
- Hist
from hist import Hist
- Hist.new
from hist import Hist; h = Hist.new.Reg(10, 0, 1, name='x')
Quickstart
from hist import Hist
import numpy as np
# Create a histogram with one regular axis
h = (Hist.new
.Reg(10, 0, 10, name="x", label="X-axis [units]")
.Double() # Storage type
)
# Fill the histogram with some data
data = np.random.normal(5, 1, 1000)
h.fill(x=data)
# Access counts and plot (requires matplotlib, optional install)
# import matplotlib.pyplot as plt
# h.plot()
# plt.show()
print(h)