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.
pip install histVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple 1D histogram using Hist's `Hist.new` quick construction, fill it with NumPy array data, and print its representation. The example also shows how to define named and labeled axes. Plotting functionality is available with the `[plot]` extra.
Ensure your environment uses Python 3.10 or newer. Upgrade your Python version if necessary.
Upgrade `boost-histogram` to the latest compatible version (e.g., `pip install --upgrade boost-histogram`). Consult `hist` release notes for specific version requirements.
Install with `pip install "hist[plot,fit]"` to ensure all previously available features are present.
Always remember to call `.compute()` on Dask-backed `hist` objects to get the final in-memory histogram for inspection, plotting, or further non-Dask operations.
When creating histograms, always provide a `name` argument for each axis (e.g., `Hist.new.Reg(..., name='my_axis')`). Consider using `from hist import NamedHist` for stricter enforcement.
If you intend to use weighted fills and need variance calculations, ensure you initialize your histogram with a weighted storage type (e.g., `hist.storage.Weight()`).
Install the library using pip: `pip install hist` or `python3 -m pip install "hist[plot,fit]"` to include plotting and fitting capabilities.
Import the `Hist` class directly using `from hist import Hist` and then instantiate it as `Hist(...)`.
Ensure that each axis defined within a single `Hist` object has a unique `name` parameter, for example: `hist.axis.Regular(10, 0, 10, name="x_axis")` and `hist.axis.Regular(10, 0, 10, name="y_axis")`.
Provide the `bins`, `low`, and `high` values when defining a regular axis, e.g., `h = Hist.new.Reg(50, -5, 5, name="my_axis").Double()` or `hist.axis.Regular(50, -5, 5, name="my_axis")`.