figuratively 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- figuratively-1.0.0/.gitignore +12 -0
- figuratively-1.0.0/AUTHORS.md +20 -0
- figuratively-1.0.0/CHANGELOG.md +33 -0
- figuratively-1.0.0/CITATION.cff +20 -0
- figuratively-1.0.0/CONTRIBUTING.md +21 -0
- figuratively-1.0.0/LICENSE +21 -0
- figuratively-1.0.0/NOTICE +42 -0
- figuratively-1.0.0/PKG-INFO +364 -0
- figuratively-1.0.0/README.md +322 -0
- figuratively-1.0.0/SECURITY.md +25 -0
- figuratively-1.0.0/examples/gallery/01_fit_components.py +7 -0
- figuratively-1.0.0/examples/gallery/02_data_mc_ratio.py +6 -0
- figuratively-1.0.0/examples/gallery/03_stack_log.py +5 -0
- figuratively-1.0.0/examples/gallery/04_hist2d.py +5 -0
- figuratively-1.0.0/examples/gallery/_toy.py +50 -0
- figuratively-1.0.0/pyproject.toml +71 -0
- figuratively-1.0.0/src/figuratively/__init__.py +34 -0
- figuratively-1.0.0/src/figuratively/_rootcolor_table.py +22 -0
- figuratively-1.0.0/src/figuratively/auto.py +908 -0
- figuratively-1.0.0/src/figuratively/checks.py +153 -0
- figuratively-1.0.0/src/figuratively/cli.py +106 -0
- figuratively-1.0.0/src/figuratively/colors.py +217 -0
- figuratively-1.0.0/src/figuratively/data.py +518 -0
- figuratively-1.0.0/src/figuratively/explore.py +134 -0
- figuratively-1.0.0/src/figuratively/figuratively.h +76 -0
- figuratively-1.0.0/src/figuratively/options.py +157 -0
- figuratively-1.0.0/src/figuratively/plot.py +1139 -0
- figuratively-1.0.0/src/figuratively/py.typed +0 -0
- figuratively-1.0.0/src/figuratively/style.py +75 -0
- figuratively-1.0.0/tests/conftest.py +7 -0
- figuratively-1.0.0/tests/test_basic.py +113 -0
- figuratively-1.0.0/tests/test_checks.py +184 -0
- figuratively-1.0.0/tests/test_colors.py +104 -0
- figuratively-1.0.0/tests/test_custom.py +234 -0
- figuratively-1.0.0/tests/test_fixes.py +342 -0
- figuratively-1.0.0/tests/test_robust.py +127 -0
- figuratively-1.0.0/tests/test_root_integration.py +171 -0
- figuratively-1.0.0/tests/test_security.py +192 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Authors
|
|
2
|
+
|
|
3
|
+
- **Abhishek Bohare** (The University of Edinburgh, UK): author and maintainer. Concept, direction, testing against real analysis files, release.
|
|
4
|
+
|
|
5
|
+
## How it was built
|
|
6
|
+
|
|
7
|
+
Figuratively was developed by Abhishek Bohare with AI assistance (Claude Code, by Anthropic). The AI wrote and
|
|
8
|
+
reviewed code and tests under the author's direction; the author decided what to build, tested the tool on real
|
|
9
|
+
RooFit canvases and is responsible for the project. This is stated openly because it is the honest description of
|
|
10
|
+
how the software was made.
|
|
11
|
+
|
|
12
|
+
## Standing on the shoulders of
|
|
13
|
+
|
|
14
|
+
- [uproot](https://github.com/scikit-hep/uproot5) (reads ROOT files without ROOT) and
|
|
15
|
+
[mplhep](https://github.com/scikit-hep/mplhep) (HEP plot styles), by the Scikit-HEP community;
|
|
16
|
+
- [matplotlib](https://matplotlib.org) for all drawing;
|
|
17
|
+
- the [ROOT](https://root.cern) and RooFit developers, whose file format and conventions this tool reads;
|
|
18
|
+
- [JSROOT](https://github.com/root-project/jsroot), from whose public source the ROOT colour table was extracted;
|
|
19
|
+
- R's colour work (the 4.0 default palette, `hcl.colors`, Okabe and Ito's palette), which inspired the colour
|
|
20
|
+
translation.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. Format: Keep a Changelog; versioning: SemVer.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-11-25
|
|
6
|
+
### Added
|
|
7
|
+
- `figuratively.plot("file.root:object")`: RooFit canvases (data, total, components, pulls), data/MC overlays with
|
|
8
|
+
ratio panel, 2D histograms, graphs, whole-file batch mode.
|
|
9
|
+
- `figly` / `figuratively` command line, `figuratively.toml` project configuration.
|
|
10
|
+
- Reading of ROOT `TCanvas` objects without ROOT (via uproot, with a guarded fallback).
|
|
11
|
+
- "Did you mean" errors for missing objects, notebook inline display.
|
|
12
|
+
- Customisation: `components=` (compact style strings), `merge=`, `order=`, `styles=`, `blind=`, labelled
|
|
13
|
+
`vline` / `hline` / `span`, size presets (`column`, `double`, `slide`), `scale_x`, `rebin`, `dpi`, `legend` forms.
|
|
14
|
+
- Discovery: `fg.options()`, `fg.inspect()`, `figly inspect`, `figly init`, "did you mean" for options and
|
|
15
|
+
component names, `strict=True`.
|
|
16
|
+
- Colours: ROOT colour indices are translated into refined colours (hue kept, lightness and chroma tamed,
|
|
17
|
+
neighbours kept visibly apart), plus R-style palettes (`r4`, `okabe-ito`, `tableau10`, `dark2`, `hcl`).
|
|
18
|
+
- ROOT integration: `fg.plot(canvas)` with live PyROOT objects, a C++ header (`figly header`) with
|
|
19
|
+
`Figuratively::Plot(canvas)`, and the `figly` command for any `.root` file.
|
|
20
|
+
- Multi-panel canvases give one figure per panel; the text written on the canvas (e.g. the bin range) becomes an
|
|
21
|
+
info line; a wrong object name falls back to the only object in the file; unreadable objects in a canvas are skipped.
|
|
22
|
+
- Renaming: `labels` (dict or list, including `data` and `total`), `Plot.rename`, and settable built-in texts.
|
|
23
|
+
- Safeguards: `fg.check`, `fg.summary` (text, csv, latex), `figly check` / `figly summary`, warnings for a mis-scaled
|
|
24
|
+
curve, huge pulls, empty bins, silent normalisation, a leaking blind window and undrawn canvas objects
|
|
25
|
+
(`checks=False`, `strict=True`). Pulls use RooFit's bin-averaged curve; the pull range grows with large pulls.
|
|
26
|
+
- Canvas fidelity: pad log scales and the frame x range are used as defaults.
|
|
27
|
+
- Workflow: presets (built-in and your own), glob and list inputs, `view=True`, comparison of several fits,
|
|
28
|
+
`combine=True` for one figure with all panels of a canvas.
|
|
29
|
+
- Security and ethics: configuration files are trusted only if you own them and others cannot write to them, may only
|
|
30
|
+
set documented options and write inside the project; no URLs as styles; the C++ header uses an atomic temporary
|
|
31
|
+
file and quotes every argument; fuzz tests on corrupted ROOT files; `SECURITY.md`, `NOTICE`, `AUTHORS.md`.
|
|
32
|
+
### Notes
|
|
33
|
+
- No collaboration label is drawn unless the user asks for one (`label=`, `exp=`).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use Figuratively in your work, please cite it as below."
|
|
3
|
+
title: "Figuratively"
|
|
4
|
+
abstract: "Publication-quality plots from ROOT files, without a ROOT installation: RooFit canvases, multi-panel canvases, data/MC overlays, pulls and checks in one call."
|
|
5
|
+
type: software
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
date-released: 2026-11-25
|
|
8
|
+
license: MIT
|
|
9
|
+
repository-code: https://github.com/abhishekLHCb-CERN/figuratively
|
|
10
|
+
authors:
|
|
11
|
+
- family-names: "Bohare"
|
|
12
|
+
given-names: "Abhishek"
|
|
13
|
+
affiliation: "The University of Edinburgh, UK"
|
|
14
|
+
keywords:
|
|
15
|
+
- ROOT
|
|
16
|
+
- RooFit
|
|
17
|
+
- uproot
|
|
18
|
+
- matplotlib
|
|
19
|
+
- plotting
|
|
20
|
+
- high-energy physics
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thank you for helping. Figuratively is small on purpose: one call, sensible defaults, and every customisation optional.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
git clone <your fork> && cd figuratively
|
|
7
|
+
pip install -e ".[dev,docs]"
|
|
8
|
+
pytest # the whole suite, about 40 s
|
|
9
|
+
ruff check src tests # style
|
|
10
|
+
bandit -q -r src # security scan
|
|
11
|
+
python tools/update_readme.py # after changing options (the option tables are generated)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Please:
|
|
15
|
+
- add a test with every change; every option must be documented in `options.py` (a test enforces it);
|
|
16
|
+
- use toy data only in tests, examples and issues. **Never post real analysis data, unpublished results or anything
|
|
17
|
+
covered by a collaboration's rules** (blinded quantities especially);
|
|
18
|
+
- be kind. We follow the spirit of the Contributor Covenant: be respectful, assume good faith, and keep discussion
|
|
19
|
+
about the work.
|
|
20
|
+
|
|
21
|
+
By contributing you agree that your contribution is released under the MIT licence.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abhishek Bohare
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Figuratively
|
|
2
|
+
Copyright (c) 2026 Abhishek Bohare. Released under the MIT licence (see LICENSE).
|
|
3
|
+
|
|
4
|
+
This product uses the following third-party material.
|
|
5
|
+
|
|
6
|
+
1. ROOT colour table (src/figuratively/_rootcolor_table.py)
|
|
7
|
+
The numeric RGB values of ROOT's standard colours were extracted programmatically from the public JSROOT
|
|
8
|
+
source (https://github.com/root-project/jsroot), which is MIT licensed:
|
|
9
|
+
|
|
10
|
+
The MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2013-2026 JavaScript ROOT authors
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in
|
|
22
|
+
all copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
30
|
+
THE SOFTWARE.
|
|
31
|
+
|
|
32
|
+
The values themselves are ROOT's (https://root.cern, LGPL-2.1-or-later).
|
|
33
|
+
|
|
34
|
+
2. Runtime dependencies, installed separately and not redistributed here: numpy (BSD-3-Clause), matplotlib
|
|
35
|
+
(matplotlib licence, PSF-based), mplhep (MIT), uproot (BSD-3-Clause), tomli on Python < 3.11 (MIT).
|
|
36
|
+
|
|
37
|
+
3. Colour palettes: the "R4", "Okabe-Ito", "Tableau 10" and "Dark2" palettes are published colour lists (R, Okabe
|
|
38
|
+
and Ito 2008, Tableau, ColorBrewer by Cynthia Brewer); only the hex values are used.
|
|
39
|
+
|
|
40
|
+
Trademarks: ROOT, RooFit, LHC and LHCb are names of software and experiments owned by their respective
|
|
41
|
+
organisations. Figuratively is independent software. It is not affiliated with or endorsed by CERN or any
|
|
42
|
+
experiment, and it never draws an experiment label unless the user asks for it.
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: figuratively
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Figures, figuratively speaking: one call from a ROOT file to a publication plot (no ROOT install needed).
|
|
5
|
+
Project-URL: Homepage, https://github.com/abhishekLHCb-CERN/figuratively
|
|
6
|
+
Project-URL: Documentation, https://abhishekLHCb-CERN.github.io/figuratively/
|
|
7
|
+
Project-URL: Source, https://github.com/abhishekLHCb-CERN/figuratively
|
|
8
|
+
Project-URL: Issues, https://github.com/abhishekLHCb-CERN/figuratively/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/abhishekLHCb-CERN/figuratively/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Abhishek Bohare
|
|
11
|
+
Maintainer: Abhishek Bohare
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: hep,matplotlib,mplhep,particle-physics,plotting,pull-plot,roofit,root,uproot
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: matplotlib>=3.7
|
|
27
|
+
Requires-Dist: mplhep>=0.3.40
|
|
28
|
+
Requires-Dist: numpy>=1.24
|
|
29
|
+
Requires-Dist: tomli; python_version < '3.11'
|
|
30
|
+
Requires-Dist: uproot<6,>=5
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: bandit>=1.7; extra == 'dev'
|
|
33
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pip-audit>=2.6; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=7.4; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
37
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
38
|
+
Provides-Extra: docs
|
|
39
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
40
|
+
Requires-Dist: mkdocs>=1.5; extra == 'docs'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# Figuratively
|
|
44
|
+
|
|
45
|
+
**Publication-quality plots straight from ROOT files, with no ROOT installation.**
|
|
46
|
+
|
|
47
|
+
[](https://pypi.org/project/figuratively/) [](https://pypi.org/project/figuratively/) [](https://github.com/abhishekLHCb-CERN/figuratively/actions) [](https://github.com/abhishekLHCb-CERN/figuratively/blob/main/LICENSE)
|
|
48
|
+
|
|
49
|
+
<!-- Before the first release replace the relative image paths below with absolute raw URLs pinned to the
|
|
50
|
+
release tag (PyPI does not resolve relative paths):
|
|
51
|
+
https://raw.githubusercontent.com/abhishekLHCb-CERN/figuratively/v1.0.0/docs/img/01_fit_components.png -->
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
*Toy data. One call: `fg.plot("fit.root:canvas")`.*
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install figuratively
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick start
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import figuratively as fg
|
|
67
|
+
|
|
68
|
+
fg.plot("fit.root:canvas") # data, total, every component, pulls
|
|
69
|
+
fg.plot("f.root:h_data", "f.root:h_mc") # data against simulation, ratio panel added
|
|
70
|
+
fg.plot("f.root") # every histogram, graph and canvas in the file
|
|
71
|
+
fg.plot("fit.root:canvas", logy=True, stack=True, xlim=(1800, 1900), info="2018 data")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
figly fit.root:canvas # the same from the shell (also: figuratively ...)
|
|
76
|
+
figly ls fit.root # list the objects in a file
|
|
77
|
+
figly f.root:h_data f.root:h_mc -s logy=True -o out.pdf
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Plots are written to a `plots/` folder next to the ROOT file as PDF and PNG. `fg.plot` returns a `Plot`
|
|
81
|
+
object, so anything it does not do automatically can still be changed afterwards.
|
|
82
|
+
|
|
83
|
+
## What it does for you
|
|
84
|
+
|
|
85
|
+
- Reads RooFit canvases, histograms (1D and 2D), profiles and graphs with uproot and matplotlib. No ROOT needed.
|
|
86
|
+
- Detects data, total fit, components, axis titles and units (ROOT's `#gamma` and `^{+}` become mathtext).
|
|
87
|
+
- Recomputes pulls from the data and the total curve, so a stored pull pad is not required.
|
|
88
|
+
- Adds a ratio panel for data against simulation and normalises shapes when the yields differ.
|
|
89
|
+
- Places the label, information lines and legend so that they do not sit on top of the data.
|
|
90
|
+
- Whole-file mode plots every object, warns about the ones it cannot draw and carries on.
|
|
91
|
+
- Typos give "did you mean" errors, not stack traces.
|
|
92
|
+
|
|
93
|
+
## Using it with ROOT
|
|
94
|
+
|
|
95
|
+
Figuratively never needs ROOT, but it works alongside it, from Python and from C++.
|
|
96
|
+
|
|
97
|
+
**From PyROOT** (live objects, no file to save first):
|
|
98
|
+
```python
|
|
99
|
+
import ROOT, figuratively as fg
|
|
100
|
+
fg.plot(canvas) # a TCanvas, TPad, TH1, TH2, TGraph or RooPlot you just made
|
|
101
|
+
fg.plot(h_data, h_mc) # overlay with a ratio panel
|
|
102
|
+
fg.plot(canvas, logy=True, label="Work in progress")
|
|
103
|
+
```
|
|
104
|
+
ROOT writes the object to a temporary file and Figuratively reads that file, so every feature (several panels,
|
|
105
|
+
colours, pulls, `labels=`, ...) behaves exactly as it does for a saved file. Plots go to `./plots/` unless you pass
|
|
106
|
+
`outdir=`.
|
|
107
|
+
|
|
108
|
+
**From a ROOT macro or C++ program**, one call with the small header that ships with the package:
|
|
109
|
+
```bash
|
|
110
|
+
figly header figuratively.h # copies the header next to your code
|
|
111
|
+
```
|
|
112
|
+
```cpp
|
|
113
|
+
#include "figuratively.h"
|
|
114
|
+
void make() {
|
|
115
|
+
// ... fill your canvas as usual ...
|
|
116
|
+
Figuratively::Plot(canvas); // pdf + png in the current folder
|
|
117
|
+
Figuratively::Plot(canvas, {"logy=True", "label=Work in progress"}); // any option of fg.plot, as key=value
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
Without the header, two lines in any macro do the same: `canvas->SaveAs("c.root"); gSystem->Exec("figly c.root");`.
|
|
121
|
+
`figly` must be on the PATH (`pip install figuratively`). Keywords with spaces are fine, because each one is quoted.
|
|
122
|
+
|
|
123
|
+
Honest note: the PyROOT path and the C++ header are tested against stand-ins (a fake `ROOT` module, and ROOT-like
|
|
124
|
+
headers the C++ compiles against), since CI has no ROOT installation. The file path, which is what both of them
|
|
125
|
+
use underneath, is tested on real ROOT files.
|
|
126
|
+
|
|
127
|
+
## Trust the figure: checks and tables
|
|
128
|
+
|
|
129
|
+
A plot that looks fine can still be wrong. Figuratively checks the numbers behind it and speaks up:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
fg.check("fit.root:canvas", nparams=10) # per panel: data vs curve integral, chi2/ndf, empty bins, largest pull
|
|
133
|
+
fg.summary("fit.root", nparams=10) # one row per panel: entries, chi2/ndf, yield of every component
|
|
134
|
+
fg.summary(files, fmt="latex") # or fmt="csv": ready for a systematics table
|
|
135
|
+
```
|
|
136
|
+
```bash
|
|
137
|
+
figly check fit.root:canvas -s nparams=10
|
|
138
|
+
figly summary fit.root -s fmt=csv
|
|
139
|
+
```
|
|
140
|
+
While plotting, a warning appears when the curve and the data disagree in normalisation, when many pulls exceed 5,
|
|
141
|
+
when most bins are empty, when histograms were normalised automatically, when a blinded window still shows the model
|
|
142
|
+
curve, and when the canvas holds objects that are not drawn (a `TLegend`, a stats box, a line). `checks=False`
|
|
143
|
+
silences them and `strict=True` turns them into errors, for scripts and CI. Pulls follow RooFit's convention
|
|
144
|
+
(the curve averaged over each bin); `pull={"mode": "centre"}` uses the bin centre instead.
|
|
145
|
+
|
|
146
|
+
What the canvas itself says is respected: its log scales, and the frame's x range (which also trims the stub of curve
|
|
147
|
+
that RooFit stores beyond the data). A keyword on the call always wins.
|
|
148
|
+
|
|
149
|
+
## Project defaults
|
|
150
|
+
|
|
151
|
+
Put your recurring choices in a `figuratively.toml` next to your files (or call `fg.configure(...)`):
|
|
152
|
+
|
|
153
|
+
```toml
|
|
154
|
+
label = "Work in progress" # text at the top left; nothing is drawn unless you ask for it
|
|
155
|
+
exp = "" # collaboration name; set it only if you are entitled to use it
|
|
156
|
+
com = "13" # adds "sqrt(s) = 13 TeV"
|
|
157
|
+
lumi = "5.4"
|
|
158
|
+
nparams = 14 # adds chi2/ndf to fit plots
|
|
159
|
+
formats = ["pdf", "png"]
|
|
160
|
+
|
|
161
|
+
[labels] # legend text per object or component name
|
|
162
|
+
sig = '$X\to\gamma\gamma$'
|
|
163
|
+
comb = "Combinatorial"
|
|
164
|
+
|
|
165
|
+
[colors]
|
|
166
|
+
sig = "#0072B2"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Every keyword of `fg.plot` is either one of these keys (a per-call override) or a method of `Plot`
|
|
170
|
+
(`logy`, `xlim`, `ylim`, `legend`, `font`, `text`, `vline`, `info`, ...). An unknown keyword raises an error.
|
|
171
|
+
|
|
172
|
+
## Customise when you need to
|
|
173
|
+
|
|
174
|
+
You never have to. Everything below is optional, and each step is one more keyword on the same call:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
fg.plot("fit.root:canvas") # nothing to configure
|
|
178
|
+
fg.plot("fit.root:canvas", logy=True, xlim=(1800, 1900)) # a few keywords
|
|
179
|
+
fg.plot("fit.root:canvas", components={"sig": "red dashed fill", "bkg*": {"alpha": 0.4}},
|
|
180
|
+
merge={"Backgrounds": ["comb", "bkg*"]}, order=["Backgrounds", "sig"])
|
|
181
|
+
fg.plot("fit.root:canvas", blind=(1840, 1890), vline=[(1865, "$m_{D^0}$")], span=(1850, 1880, "signal"),
|
|
182
|
+
size="column", legend="upper left", dpi=300)
|
|
183
|
+
p = fg.plot("fit.root:canvas", save=False).logy().param("$N$", 1234, 12) # chainable Plot methods
|
|
184
|
+
p.annotate(lambda fig, ax, rax: ax.axvline(1865, ls=":")); p.save("fig.pdf")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Not sure what a canvas contains or what to call things? Ask it:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
fg.inspect("fit.root:canvas") # lists the components and prints a call to copy and edit
|
|
191
|
+
fg.options() # every option with a one-line description
|
|
192
|
+
```
|
|
193
|
+
```bash
|
|
194
|
+
figly inspect fit.root:canvas # the same from the shell
|
|
195
|
+
figly init fit.root:canvas # writes figuratively.toml with every detected component pre-filled
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
A typo never passes silently: `lgy=True` and `labels={"sgi": ...}` both say what you probably meant, and
|
|
199
|
+
`strict=True` turns such warnings into errors. A component style is a string of plain words (a colour,
|
|
200
|
+
`solid dashed dotted dashdot`, `line fill band`, `thin thick`, `alpha=0.4`, `hatch=//`) or a dict.
|
|
201
|
+
Settings resolve in this order: keyword on the call, then `figuratively.toml`, then the built-in default.
|
|
202
|
+
|
|
203
|
+
### Colours, learned from R
|
|
204
|
+
|
|
205
|
+
A canvas written by a ROOT macro carries its colours as indices (`kRed`, `kGreen+3`, ...), and ROOT's colours
|
|
206
|
+
are the saturated primaries of the 1990s. Figuratively reads them and **translates** them instead of copying
|
|
207
|
+
them (`root_colors=True`, the default):
|
|
208
|
+
|
|
209
|
+
- the **hue** is kept, so a red curve in your macro is still a red curve, and ROOT's line styles and fills
|
|
210
|
+
carry over too;
|
|
211
|
+
- the lightness is squeezed into a band that reads well on white and the chroma is capped, so nothing screams
|
|
212
|
+
and nothing vanishes. The light-to-dark order of ROOT's shades (`kRed-4` ... `kRed+3`) is preserved;
|
|
213
|
+
- colours that end up too similar (three shades of orange in one canvas, say) are moved apart until they
|
|
214
|
+
are clearly distinguishable, measured in the perceptual OKLab space.
|
|
215
|
+
|
|
216
|
+
This follows what R did: its 4.0 release replaced the old garish default palette with tamed tones, and its
|
|
217
|
+
`hcl.colors` builds palettes from evenly spaced hues at equal lightness. For components without a ROOT colour
|
|
218
|
+
(or with `root_colors=False`) pick a palette with `palette="r4"`, `"okabe-ito"` (colour-blind safe),
|
|
219
|
+
`"tableau10"`, `"dark2"` or `"hcl"`. Every palette is extended with evenly spaced HCL hues, so thirty
|
|
220
|
+
components never repeat a colour. `fg.root_color(632)` and `fg.palette("hcl", 12)` give you the colours directly.
|
|
221
|
+
|
|
222
|
+
The ROOT colour table was extracted programmatically from the public JSROOT source, so no value is typed by hand.
|
|
223
|
+
|
|
224
|
+
### All options
|
|
225
|
+
|
|
226
|
+
<!-- options:start -->
|
|
227
|
+
**Fit components**
|
|
228
|
+
|
|
229
|
+
| Option | Effect |
|
|
230
|
+
|---|---|
|
|
231
|
+
| `components` | per-component style: {'sig': 'red dashed fill', 'bkg*': {'alpha': .4}} |
|
|
232
|
+
| `labels` | rename legend entries: {'sig': 'Signal', 'data': 'Data', 'total': 'Fit'} or just a list in legend order ['Data', 'Fit', 'Signal', ...] |
|
|
233
|
+
| `colors` | colour per object or component: {'sig': '#0072B2'} |
|
|
234
|
+
| `styles` | full per-component style dicts: {'comb': {'kind': 'fill', 'hatch': '//'}} |
|
|
235
|
+
| `comp_kind` | default drawing style of every component: 'line', 'fill' or 'band' |
|
|
236
|
+
| `merge` | sum several components into one entry: {'Backgrounds': ['comb', 'bkg*']} |
|
|
237
|
+
| `hide` | regular expressions of components to leave out |
|
|
238
|
+
| `order` | component order in the legend and the stack |
|
|
239
|
+
| `stack` | stack the components as filled areas |
|
|
240
|
+
| `root_colors` | True takes colours, line styles and fills from the ROOT objects (refined, and kept visibly apart); 'components' leaves the total in the house colour; False ignores ROOT |
|
|
241
|
+
| `palette` | colours for components without a ROOT colour: figuratively, r4, okabe-ito, tableau10, dark2, hcl |
|
|
242
|
+
|
|
243
|
+
**Panels**
|
|
244
|
+
|
|
245
|
+
| Option | Effect |
|
|
246
|
+
|---|---|
|
|
247
|
+
| `pull` | False to drop the pull panel, or a dict of Plot.pull options: {'ylim': (-4, 4), 'mode': 'centre'}; the range grows beyond +-5 by itself when the pulls are larger |
|
|
248
|
+
| `nparams` | number of fit parameters; adds chi2/ndf to the info block |
|
|
249
|
+
| `ratio` | False to drop the ratio panel, or its y-range: (0.7, 1.3) |
|
|
250
|
+
| `pull_label` | y-label of the pull panel |
|
|
251
|
+
| `ratio_label` | y-label of the ratio panel |
|
|
252
|
+
|
|
253
|
+
**Histograms**
|
|
254
|
+
|
|
255
|
+
| Option | Effect |
|
|
256
|
+
|---|---|
|
|
257
|
+
| `normalise` | normalise every histogram to unit area |
|
|
258
|
+
| `rebin` | merge N neighbouring bins |
|
|
259
|
+
| `kind` | drawing style of histograms: 'step', 'fill', 'points' or 'band' |
|
|
260
|
+
| `data_pattern` | regular expression that marks an object as data |
|
|
261
|
+
|
|
262
|
+
**Regions, lines and text**
|
|
263
|
+
|
|
264
|
+
| Option | Effect |
|
|
265
|
+
|---|---|
|
|
266
|
+
| `blind` | hide data in a window and mark it: (1840, 1890) or [(a, b), (c, d)] |
|
|
267
|
+
| `blind_curves` | with blind=: also blank the model curves inside the window |
|
|
268
|
+
| `vline` | vertical line(s): 1865, (1865, 'label') or a list of those |
|
|
269
|
+
| `hline` | horizontal line(s): 100, (100, 'label') or a list of those |
|
|
270
|
+
| `span` | shaded window(s): (x0, x1) or (x0, x1, 'label') or a list of those |
|
|
271
|
+
| `text` | text at axes fractions: (0.05, 0.9, 'text') or a list of those |
|
|
272
|
+
| `canvas_text` | text written on the canvas (e.g. the bin range): True shows it, False hides it, a dict {old: new} edits it, a function f(text, panel) rewrites it (return None to drop) |
|
|
273
|
+
| `blind_label` | text inside a blinded band (a window can also carry its own: (lo, hi, 'text')) |
|
|
274
|
+
| `info` | small text lines in the top-right block (string or list) |
|
|
275
|
+
| `label` | top-left label text, e.g. 'Work in progress' (none by default) |
|
|
276
|
+
| `exp` | collaboration name in the label; empty by default, set it only if you are entitled to |
|
|
277
|
+
| `com` | centre-of-mass energy in TeV for the label, e.g. '13' |
|
|
278
|
+
| `lumi` | integrated luminosity in fb^-1 for the label |
|
|
279
|
+
| `data` | False prints 'Simulation' in the label |
|
|
280
|
+
|
|
281
|
+
**Axes**
|
|
282
|
+
|
|
283
|
+
| Option | Effect |
|
|
284
|
+
|---|---|
|
|
285
|
+
| `ylabel_prefix` | start of the automatic y-label, e.g. 'Events' gives 'Events / (2 MeV)' |
|
|
286
|
+
| `xlim` | x range (lo, hi); None keeps a side automatic |
|
|
287
|
+
| `ylim` | y range (lo, hi) |
|
|
288
|
+
| `xrange` | alias of xlim |
|
|
289
|
+
| `yrange` | alias of ylim |
|
|
290
|
+
| `logx` | logarithmic x axis |
|
|
291
|
+
| `logy` | logarithmic y axis |
|
|
292
|
+
| `log` | 'x', 'y' or 'xy': shorthand for logx / logy |
|
|
293
|
+
| `xlabel` | x label, or (text, unit) |
|
|
294
|
+
| `ylabel` | y label (default is generated from the bin width) |
|
|
295
|
+
| `unit` | unit used in the axis labels and the bin-width label |
|
|
296
|
+
| `scale_x` | multiply the x axis, e.g. 1e-3 for MeV to GeV (set unit= too) |
|
|
297
|
+
| `title` | figure title |
|
|
298
|
+
| `grid` | draw a grid |
|
|
299
|
+
| `headroom` | factor of free space above the data |
|
|
300
|
+
|
|
301
|
+
**Figure**
|
|
302
|
+
|
|
303
|
+
| Option | Effect |
|
|
304
|
+
|---|---|
|
|
305
|
+
| `preset` | a named bundle of settings: thesis, paper, slides, poster, or one of your own from the [presets.NAME] tables of figuratively.toml; the call's own keywords always win |
|
|
306
|
+
| `presets` | your own presets as a dict {name: {option: value}} (usually written in figuratively.toml) |
|
|
307
|
+
| `size` | figure size (w, h) in inches or a preset: 'column', 'double', 'slide' |
|
|
308
|
+
| `figsize` | alias of size |
|
|
309
|
+
| `font` | scale every text size |
|
|
310
|
+
| `legend` | False, a location string, or a dict(loc=, ncol=, title=) |
|
|
311
|
+
| `style` | mplhep style name or path of a .mplstyle file |
|
|
312
|
+
| `data_label` | legend text of the data |
|
|
313
|
+
| `total_label` | legend text of the total fit |
|
|
314
|
+
|
|
315
|
+
**Output**
|
|
316
|
+
|
|
317
|
+
| Option | Effect |
|
|
318
|
+
|---|---|
|
|
319
|
+
| `formats` | file formats to write |
|
|
320
|
+
| `suffix` | text added to the automatic file name, so variants do not overwrite each other: '_stack_log' |
|
|
321
|
+
| `checks` | warn about a curve that does not match the data, huge pulls, a leaking blind window, silent normalisation and objects of the canvas that are not drawn (False silences them) |
|
|
322
|
+
| `view` | open the saved figure in your default viewer when done |
|
|
323
|
+
| `outdir` | folder for the output, relative to the ROOT file |
|
|
324
|
+
| `dpi` | resolution of raster output |
|
|
325
|
+
| `transparent` | transparent background |
|
|
326
|
+
| `strict` | turn warnings about unmatched names into errors |
|
|
327
|
+
<!-- options:end -->
|
|
328
|
+
|
|
329
|
+
For finer control use the `Plot` class directly: `fg.Plot().add(...).ratio().label(...).save(...)`, or the
|
|
330
|
+
raw matplotlib objects `p.fig`, `p.ax` and `p.rax`.
|
|
331
|
+
|
|
332
|
+
## Gallery
|
|
333
|
+
|
|
334
|
+
Every image below is produced by a script in `examples/gallery/` from toy data with a fixed random seed.
|
|
335
|
+
|
|
336
|
+
| | |
|
|
337
|
+
|---|---|
|
|
338
|
+
|  |  |
|
|
339
|
+
|  | |
|
|
340
|
+
|
|
341
|
+
## Notes
|
|
342
|
+
|
|
343
|
+
- No collaboration label is drawn unless you ask for one with `label=` and `exp=`. Figuratively is not
|
|
344
|
+
affiliated with or endorsed by any experiment; using a collaboration label is your responsibility.
|
|
345
|
+
- Canvases are read through a fallback, because uproot cannot parse `TCanvas` directly. If a canvas fails to
|
|
346
|
+
load, the error says so; saving the `RooPlot` or the histograms themselves always works.
|
|
347
|
+
- Built on [uproot](https://github.com/scikit-hep/uproot5) and [mplhep](https://github.com/scikit-hep/mplhep)
|
|
348
|
+
(both BSD-3-Clause) and matplotlib.
|
|
349
|
+
|
|
350
|
+
## Licence
|
|
351
|
+
|
|
352
|
+
MIT. See `LICENSE`.
|
|
353
|
+
|
|
354
|
+
## Credit and citation
|
|
355
|
+
|
|
356
|
+
Figuratively is written and maintained by **Abhishek Bohare**, with AI assistance (Claude Code); see `AUTHORS.md`.
|
|
357
|
+
If it helps your work, please cite it (`CITATION.cff` is understood by GitHub and Zenodo):
|
|
358
|
+
|
|
359
|
+
> Bohare, A. (2026). *Figuratively: publication-quality plots from ROOT files* (version 1.0.0).
|
|
360
|
+
|
|
361
|
+
## Safety
|
|
362
|
+
|
|
363
|
+
No network access, no telemetry, no shell. Configuration files are used only if you own them and nobody else can
|
|
364
|
+
write to them, and they can only set documented options. Open only ROOT files you trust. Details in `SECURITY.md`.
|