Hist classes and utilities
Project description
Hist
Hist is an analyst-friendly front-end for boost-histogram, designed for Python 3.10+ (3.6-3.9 users get older versions). See what's new.
Installation
You can install this library from PyPI with pip:
python3 -m pip install "hist[plot,fit]"
If you do not need the plotting features, you can skip the [plot] and/or
[fit] extras. [fit] is not currently supported in WebAssembly.
Features
Hist currently provides everything boost-histogram provides, and the following enhancements:
-
Hist augments axes with names:
name=is a unique label describing each axis.label=is an optional string that is used in plotting (defaults tonameif not provided).- Indexing, projection, and more support named axes.
- Experimental
NamedHistis aHistthat disables most forms of positional access, forcing users to use only names.
-
The
Histclass augmentsbh.Histogramwith simpler construction:flow=Falseis a fast way to turn off flow for the axes on construction.storage=can be omitted, strings and storages can be positional.data=can initialize a histogram with existing data.Hist.from_columnscan be used to initialize with a DataFrame or dict.- You can cast back and forth with boost-histogram (or any other extensions).
-
Hist support QuickConstruct, an import-free construction system that does not require extra imports:
- Use
Hist.new.<axis>().<axis>().<storage>(). - Axes names can be full (
Regular) or short (Reg). - Histogram arguments (like
data=) can go in the storage.
- Use
-
Extended Histogram features:
- Direct support for
.nameand.label, like axes. .density()computes the density as an array..profile(remove_ax)can convert a ND COUNT histogram into a (N-1)D MEAN histogram..sort(axis)supports sorting a histogram by a categorical axis. Optionally takes a function to sort by..fill_flattened(...)will flatten and fill, including support for AwkwardArray..integrate(...), which takes the opposite arguments as.project.
- Direct support for
-
Hist implements UHI+; an extension to the UHI (Unified Histogram Indexing) system designed for import-free interactivity:
- Uses
jsuffix to switch to data coordinates in access or slices. - Uses
jsuffix on slices to rebin. - Strings can be used directly to index into string category axes.
- Uses
-
Quick plotting routines encourage exploration:
.plot()provides 1D and 2D plots (or useplot1d(),plot2d()).plot2d_full()shows 1D projects around a 2D plot..plot_ratio(...)make a ratio plot between the histogram and another histogram or callable..plot_pull(...)performs a pull plot..plot_pie()makes a pie plot..show()provides a nice str printout using Histoprint.
-
Stacks: work with groups of histograms with identical axes
- Stacks can be created with
h.stack(axis), using index or name of an axis (StrCategoryaxes ideal). - You can also create with
hist.stacks.Stack(h1, h2, ...), or usefrom_iterorfrom_dict. - You can index a stack, and set an entry with a matching histogram.
- Stacks support
.plot()and.show(), with names (plot labels default to original axes info). - Stacks pass through
.project,*,+, and-.
- Stacks can be created with
-
New modules
intervalssupports frequentist coverage intervals.
-
Notebook ready: Hist has gorgeous in-notebook representation.
- No dependencies required
Usage
from hist import Hist
# Quick construction, no other imports needed:
h = (
Hist.new.Reg(10, 0, 1, name="x", label="x-axis")
.Var(range(10), name="y", label="y-axis")
.Int64()
)
# Filling by names is allowed:
h.fill(y=[1, 4, 6], x=[0.3, 0.5, 0.2])
# Names can be used to manipulate the histogram:
h.project("x")
h[{"y": 0.5j + 3, "x": 5j}]
# You can access data coordinates or rebin with a `j` suffix:
h[0.3j:, ::2j] # x from .3 to the end, y is rebinned by 2
# Elegant plotting functions:
h.plot()
h.plot2d_full()
h.plot_pull(Callable)
Development
From a git checkout, either use nox, or run:
python -m pip install -e .[dev]
See Contributing guidelines for information on setting up a development environment.
Contributors
We would like to acknowledge the contributors that made this project possible (emoji key):
This project follows the all-contributors specification.
Talks
- 2021-07-07 PyHEP 2021 -- High-Performance Histogramming for HEP Analysis 🎥
- 2020-09-08 IRIS-HEP/GSOC -- Hist: histogramming for analysis powered by boost-histogram 🎥
- 2020-07-07 SciPy Proceedings 🎥
- 2020-07-17 PyHEP 2020 🎥
Acknowledgements
This library was primarily developed by Henry Schreiner and Nino Lau.
Support for this work was provided by the National Science Foundation cooperative agreement OAC-1836650 (IRIS-HEP) and OAC-1450377 (DIANA/HEP). Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hist-2.10.1.tar.gz.
File metadata
- Download URL: hist-2.10.1.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dec8e6ac79a6d64ec8873cf36b3ef0394c79aff3b0e8abed71fdc77fdc421b2e
|
|
| MD5 |
f2e4fc4aa3e58f7046a48a0e236c026c
|
|
| BLAKE2b-256 |
ea19675006ed34998073e851f837c129172fb93115e056b54382f4f8b1c6392e
|
Provenance
The following attestation bundles were made for hist-2.10.1.tar.gz:
Publisher:
cd.yml on scikit-hep/hist
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hist-2.10.1.tar.gz -
Subject digest:
dec8e6ac79a6d64ec8873cf36b3ef0394c79aff3b0e8abed71fdc77fdc421b2e - Sigstore transparency entry: 919717430
- Sigstore integration time:
-
Permalink:
scikit-hep/hist@f9f236112aa9d439cf8fd2fcf7bb2c4bc8feb4d8 -
Branch / Tag:
refs/tags/v2.10.1 - Owner: https://github.com/scikit-hep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@f9f236112aa9d439cf8fd2fcf7bb2c4bc8feb4d8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hist-2.10.1-py3-none-any.whl.
File metadata
- Download URL: hist-2.10.1-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
890c05ab3cf9b64c474a3c84f64bc768bd8d85b1728f449d7dc210248583657e
|
|
| MD5 |
8a91fe4c0d2c0901d5600b19210f6b7b
|
|
| BLAKE2b-256 |
9ad5406972d1ffcab016331a3198d8981b46d7685be19535998e35929080d921
|
Provenance
The following attestation bundles were made for hist-2.10.1-py3-none-any.whl:
Publisher:
cd.yml on scikit-hep/hist
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hist-2.10.1-py3-none-any.whl -
Subject digest:
890c05ab3cf9b64c474a3c84f64bc768bd8d85b1728f449d7dc210248583657e - Sigstore transparency entry: 919717433
- Sigstore integration time:
-
Permalink:
scikit-hep/hist@f9f236112aa9d439cf8fd2fcf7bb2c4bc8feb4d8 -
Branch / Tag:
refs/tags/v2.10.1 - Owner: https://github.com/scikit-hep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@f9f236112aa9d439cf8fd2fcf7bb2c4bc8feb4d8 -
Trigger Event:
release
-
Statement type: