Skip to main content

rootfig

Publication-quality figures straight from ROOT trees, without ROOT.

Documentation · Gallery · Quick start

Documentation DOI CI Key4hep codecov PyPI Python License

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.

Logarithmic axes with log-spaced bins    Two-dimensional histogram

Broken x axis with a ratio panel    FCC-ee stack scaled to luminosity with a significance panel

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.

Samples that belong to one physics category are drawn as one histogram with rf.Group. Each keeps its own files, weights, cross section and systematics; they are summed only after filling:

ww = rf.Sample("ww.root", tree="events", label="WW", weight="mc_weight")
zz = rf.Sample("zz.root", tree="events", label="ZZ", weight="mc_weight")
vv = rf.Group([ww, zz], label="VV")

rf.plot([vv, signal], pt, observed=data, stack=True, ratio=True, style=style)

Whole sets of plots, every variable under each selection in every drawing variant, are one rf.PlotBook: it runs that same rf.plot call per combination and writes deterministically named files:

book = rf.PlotBook(
    [vv, signal],
    [pt, rf.Variable("MET", bins=(40, 0, 200), unit="GeV")],
    selections={"baseline": baseline, "sr": baseline & "MET > 50"},
    variants={"lin": {}, "log": {"logy": True}},
    plot_kwargs={"observed": data, "stack": True, "ratio": True, "style": style},
)
book.save("plots/", formats=["pdf", "png"])  # plots/Muon_pt__sr__log.pdf, ...
book.save_pdf("overview.pdf")  # one automatically arranged multipage PDF

rf.ALL discovers the variables instead, from the branch types and stored histograms of the files (metadata only), filtered by name:

book = rf.PlotBook(
    [vv, signal],
    variables=rf.ALL,
    exclude=["*_cov", "*Index"],
)

What you can do

  • Select events and objects with readable expressions. Write cuts such as count(Jet_pt) >= 2 or Muon_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 -999 sentinels do not set the axis. Normalise to unity, density, bin width or luminosity. Draw several samples as one histogram with rf.Group, each keeping its own weights, cross section and systematics.
  • 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.
  • Produce whole sets of plots. rf.PlotBook runs one rf.plot call over variables × selections × variants, lazily, and saves each under a deterministic name or all of them as one multipage PDF; rf.ALL discovers the variables from the files, and select() filters the book down while iterating on a plot.
  • 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 TTree and RNTuple data, 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.

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 your histograms already exist, rf.plot draws them too: name a TH1 stored in the file instead of a branch (rf.plot("zh_histo.root", "m_recoil")), or pass hist.Hist objects directly. 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.

Release files for rootfig 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rootfig 0.7.1
File Size Uploaded
rootfig-0.7.1.tar.gz 17.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for rootfig 0.7.1
File Interpreter ABI Platform
rootfig-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 MB

Release files / rootfig-0.7.1.tar.gz

Download URL rootfig-0.7.1.tar.gz
Size 17.4 MB
Tags Source
SHA-256 checksum
How to use checksums
788db57f011380f51d398f7cb09790ce14eed572566d85e1377ee2c562b3637a
BLAKE2b-256 checksum
How to use checksums
e0080a578be78dff6b1c56fae0ba8edd4d70cba4b90cafa43c883911f1ece0a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / rootfig-0.7.1-py3-none-any.whl

Download URL rootfig-0.7.1-py3-none-any.whl
Size 209.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa17ea2aa1b4032b38c5eeb86464048ad43e9a2470906b68d67de86c11175b56
BLAKE2b-256 checksum
How to use checksums
a79319afb55fecc0b740c02186188b0b5bac749dd588905047abd6957a335a0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.0

2 release files

This release

0.7.1 This release

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page