Publication-quality figures straight from ROOT trees, without ROOT.
Documentation · Gallery · Quick start
Go from a ROOT file to a styled figure in one call. Choose a variable, add a selection, and plot:
import rootfig as rf
rf.plot("events.root", "Muon_pt", tree="events", selection="Muon_pt > 20", bins=50)
Start with a single distribution; add samples, weights, stacks and ratio panels as your analysis grows. Every plot gives you a matplotlib figure to customise and save.
Explore the gallery → See each figure alongside the code that makes it, from simple overlays to stacked data/MC comparisons, broken axes and 2D histograms, in the neutral style or in that of ATLAS, CMS, LHCb, ALICE or DUNE.
Installation
pip install rootfig
# or
uv add rootfig
Python 3.12 or newer. No ROOT installation is needed; TTree and RNTuple
files are both supported.
Compare samples in one call
import rootfig as rf
# Overlay two samples, each normalised to unity, with a Signal / Background panel.
rf.plot(
{"Signal": "signal.root", "Background": "background.root"},
"Muon_pt",
tree="events",
selection="abs(Muon_eta) < 2.5",
weight="event_weight",
bins=(50, 0, 200),
normalize=True,
ratio="Background",
)
Build up to a full analysis
Define samples, variables, cuts and styles once, then reuse them across plots:
import rootfig as rf
signal = rf.Sample("sig_*.root", tree="events", label="Signal", weight="mc_weight")
background = rf.Sample("bkg.root", tree="events", label="Background", weight="mc_weight")
data = rf.Sample("data.root", tree="events", label="Data", is_data=True)
pt = rf.Variable("Muon_pt", bins=(50, 0, 200), label=r"$p_T^{\mu}$", unit="GeV")
baseline = rf.Cut("nMuon >= 1") & "abs(Muon_eta) < 2.5"
style = rf.Style(experiment="ATLAS", status="Internal", lumi=140, com=13.6)
p = rf.plot(
[background, signal],
pt,
observed=data,
selection=baseline,
stack=True,
ratio=True,
logy=True,
style=style,
)
p.ax.set_ylim(top=1e5) # it is a normal matplotlib Axes
p.save("muon_pt.pdf")
Everything you get back is a standard object: p.fig and p.ax are
matplotlib Figure/Axes, p.hists are hist.Hist objects, and
rf.load(...) returns Awkward arrays.
What you can do
- Select events and objects with readable expressions. Write cuts such as
count(Jet_pt) >= 2orMuon_pt > 20; event and object selections have explicit rules, and event weights carry through to each selected object. - Compare samples with a few keywords. Overlays, stacks, data points and
ratio panels share binning and propagate histogram uncertainties; bin edges
and
(n, low, high)are used as given, while a range inferred from the data ignores far outliers, so-999sentinels do not set the axis. Normalise to unity, density, bin width or luminosity. - Show systematic uncertainties. Attach weight, branch, file or normalisation variations to a sample; stacks and ratio panels draw the combined statistical and systematic band, and every component stays accessible.
- Style figures for your analysis. Add experiment labels, units, log axes and broken axes, then refine the result with matplotlib.
- Go beyond 1D plots. Draw 2D histograms, correlations, efficiencies, profiles, resolutions and significance panels; produce cut flows and summary statistics from the same inputs.
- Work directly with your files. Read
TTreeandRNTupledata, combine files with globs, limit entry ranges for quick checks, and use EDM4hep split collections. Only the branches your expressions need are read.
Documentation
Read the docs or browse the gallery for examples with figures and code.
- Quick start: your first plot, selections and weights.
- Expressions and selections: syntax and event/object rules.
- Samples, variables, cuts and styles: reusable analysis definitions.
- Plotting options: binning, normalisation, panels and styling.
- API reference: full signatures and options.
Relation to the ecosystem
rootfig brings a TTree::Draw-like workflow to the Scientific Python HEP
stack, building on familiar libraries:
| Task | Library | What rootfig adds |
|---|---|---|
| Reading ROOT files | uproot | file globs, tree auto-detection, reading only the required branches |
| Jagged arrays | Awkward Array | the per-event/per-object rules for cuts and weights |
| Histograms | hist / boost-histogram | shared binning, robust automatic ranges, normalisation, ratios |
| Drawing | mplhep + matplotlib | overlays, stacks, ratio panels, labels and legends with good defaults |
If you already have hist.Hist objects, rf.plot_histograms draws them with
the same options. If you want the arrays, rf.load returns them. See
the ecosystem guide for details.
Development
git clone https://github.com/jbeirer/rootfig
cd rootfig
uv sync --all-groups
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy
See CONTRIBUTING.md for details.
Citation
If rootfig is useful in your research, please cite it:
@software{rootfig,
author = {Beirer, Joshua Falco},
doi = {10.5281/zenodo.22726311},
license = {MIT},
title = {{rootfig}},
url = {https://github.com/jbeirer/rootfig},
year = {2026}
}
License
MIT. See LICENSE.
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 rootfig-0.4.0.tar.gz.
File metadata
- Download URL: rootfig-0.4.0.tar.gz
- Upload date:
- Size: 17.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab67c22733a8288e9dc9d584d3dd1f6bd2e5e234cb4b4c1e8bc945e5e7cc898b
|
|
| MD5 |
a6674a87f11eff84600385ecaa2c1afc
|
|
| BLAKE2b-256 |
fb26fb41a09ccb7dc2f569a55e6c52f620007fc777c6d54748c4d2156749b66f
|
Provenance
The following attestation bundles were made for rootfig-0.4.0.tar.gz:
Publisher:
release.yml on jbeirer/rootfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rootfig-0.4.0.tar.gz -
Subject digest:
ab67c22733a8288e9dc9d584d3dd1f6bd2e5e234cb4b4c1e8bc945e5e7cc898b - Sigstore transparency entry: 2835924181
- Sigstore integration time:
-
Permalink:
jbeirer/rootfig@88d2ba9dedaad80d0d6b74663aaef9922e6d32e6 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/jbeirer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88d2ba9dedaad80d0d6b74663aaef9922e6d32e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rootfig-0.4.0-py3-none-any.whl.
File metadata
- Download URL: rootfig-0.4.0-py3-none-any.whl
- Upload date:
- Size: 133.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
390cd1bc0572d6354329ac6f548998f6e1a43b0ef3c50c83917d0cbdcc0829d3
|
|
| MD5 |
f692d38cdd511d486c4a8380a9fc2d87
|
|
| BLAKE2b-256 |
1d2d6eded8bc9c82c9ca7a833d5c2ae54f9e1968051ac35a6a5a9a94034ef778
|
Provenance
The following attestation bundles were made for rootfig-0.4.0-py3-none-any.whl:
Publisher:
release.yml on jbeirer/rootfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rootfig-0.4.0-py3-none-any.whl -
Subject digest:
390cd1bc0572d6354329ac6f548998f6e1a43b0ef3c50c83917d0cbdcc0829d3 - Sigstore transparency entry: 2835924207
- Sigstore integration time:
-
Permalink:
jbeirer/rootfig@88d2ba9dedaad80d0d6b74663aaef9922e6d32e6 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/jbeirer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88d2ba9dedaad80d0d6b74663aaef9922e6d32e6 -
Trigger Event:
push
-
Statement type: