Skip to content

Commit 2e55546

Browse files
jonas-eschlepre-commit-ci[bot]Copilot
authored
add DUNE style (#568)
* enh: use Times New Roman also for mathfonts * enh: change fonts to Tex Gyre Termes and redude default DPI * Add DUNE plot style from DUNE/dune_plot_style * fix: notebook example missing empty line * chore: reformat * fix: undo lhcb change * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * docs: add acknowledgements * tests: add reference images * enh: improve DUNE plot style * test: update reference * test: update reference * test: add missing reference * enh: update DUNE plot style parameters and clean up code * test: add test files for updated dune style * fix: update DUNE style name in configuration * fix: file permissions * Update src/mplhep/styles/dune.py Co-authored-by: Copilot <[email protected]> * Update src/mplhep/dune.py Co-authored-by: Copilot <[email protected]> * fix: simplify LaTeX preamble in dune.py * enh: add DUNE1 and DUNE, where DUNE is the moving label * enh: update DUNE style references to DUNE1 in configuration and documentation * enh: add DUNE and DUNE1 to style options in README * enh: add loc parameter to DUNE label and implement tests for DUNE style variants * enh: update DUNE style configuration and add tests for DUNE and DUNE1 styles * enh: increase font sizes for improved readability in DUNE style * enh: adjust font sizes for axes and legend in DUNE style * ci: add latex installation * ci: add latex installation * ci: add latex installation with apt * ci: update font installation and skip failing tests in GitHub Actions --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent 23008f6 commit 2e55546

22 files changed

+521
-155
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
name: "🐍 ${{ matrix.python-version }} • ${{ matrix.runs-on }}"
1616
runs-on: ${{ matrix.runs-on }}
1717
strategy:
18+
fail-fast: false
1819
matrix:
1920
runs-on: [ ubuntu-latest ]
2021
python-version: [ "3.8", "3.10", "3.11", "3.12", "3.13"]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ venv.bak/
115115
# PyCharm
116116
.idea/
117117
/docs/source/_generated/
118+
/tmp/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ hep.style.use(hep.style.ROOT) # For now ROOT defaults to CMS
4646
hep.style.use(hep.style.ATLAS)
4747
# or
4848
hep.style.use("CMS") # string aliases work too
49-
# {"ALICE" | "ATLAS" | "CMS" | "LHCb1" | "LHCb2"}
49+
# {"ALICE" | "ATLAS" | "CMS" | "LHCb1" | "LHCb2" | "DUNE" | "DUNE1"}
5050
```
5151

5252
Or use `matplotlib` API directly

docs/source/conf.py

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@
99
# -- Path setup --------------------------------------------------------------
1010
import importlib
1111
import inspect
12-
13-
# If extensions (or modules to document with autodoc) are in another directory,
14-
# add these directories to sys.path here. If the directory is relative to the
15-
# documentation root, use os.path.abspath to make it absolute, like shown here.
16-
#
1712
import os
1813
import subprocess
1914
import sys
2015
from functools import reduce
16+
from pathlib import Path
17+
18+
import matplotlib.pyplot as plt
19+
import numpy as np
20+
import yaml
21+
22+
import mplhep
2123

24+
# If extensions (or modules to document with autodoc) are in another directory,
25+
# add these directories to sys.path here. If the directory is relative to the
26+
# documentation root, use os.path.abspath to make it absolute, like shown here.
27+
#
2228
# Add mplhep to path for sphinx-automodapi
2329
sys.path.insert(0, os.path.abspath("../../src"))
2430

25-
from pathlib import Path
26-
27-
import mplhep
2831

2932
# -- Project information -----------------------------------------------------
3033

@@ -83,10 +86,10 @@ def linkcode_resolve(domain, info):
8386

8487

8588
intersphinx_mapping = {
86-
"python": ("https://docs.python.org/3", None),
87-
"matplotlib": ("https://matplotlib.org/stable/", None),
88-
"pandas": ("https://pandas.pydata.org/docs/", None),
89-
"numpy": ("https://numpy.org/doc/stable/", None),
89+
# "python": ("https://docs.python.org/3", None),
90+
# "matplotlib": ("https://matplotlib.org/stable/", None),
91+
# "pandas": ("https://pandas.pydata.org/docs/", None),
92+
# "numpy": ("https://numpy.org/doc/stable/", None), # stuck, takes forever
9093
}
9194

9295
# The master toctree document.
@@ -133,3 +136,62 @@ def linkcode_resolve(domain, info):
133136
# so a file named "default.css" will overwrite the builtin "default.css".
134137

135138
html_static_path = ["_static"]
139+
140+
# generate plots, moved here from index.rst
141+
142+
143+
x = np.linspace(0, 10, 100)
144+
y = np.sin(x)
145+
146+
allstyle = ["ATLAS1", "ATLAS2", "CMS", "LHCb1", "LHCb2", "ALICE", "DUNE1"]
147+
allstyle = sorted(allstyle, key=lambda s: s.lower())
148+
# allstyle = sorted(allstyle, key=lambda s: s.lower().endswith("tex"))
149+
allstyle = sorted(allstyle, key=lambda s: s.lower().endswith("alt"))
150+
here = Path("__file__").parent.resolve() # jupyter workaround, use string
151+
152+
153+
with Path(here / "_static/bkg_sig_plot.yaml").resolve().open() as f:
154+
plotdata = yaml.load(f, Loader=yaml.FullLoader)
155+
print("Creating gallery plots on the fly... (this takes a minute or two)")
156+
for style in allstyle:
157+
plt.style.use("default") # make sure it's reset
158+
plt.style.use(getattr(mplhep.style, style))
159+
160+
plot = plotdata.copy()
161+
x = np.asarray(plot.pop("x"))
162+
data = tuple(plot.pop("Data"))
163+
for histtype in ["fill", "step", "errorbar", "band"]:
164+
for position in range(5):
165+
plt.figure()
166+
ax = plt.gca()
167+
title = f"{style} {histtype}"
168+
ax.set_title(title, y=1.03)
169+
mplhep.histplot(data, histtype=histtype, label="Data", ax=ax)
170+
for label, y in plot.items():
171+
ax.plot(x, np.asarray(y), label=label)
172+
173+
kwargs = {
174+
"label": "Preliminary",
175+
"data": True,
176+
"ax": ax,
177+
"year": 2016,
178+
"loc": position,
179+
"lumi": 9,
180+
}
181+
if "atlas" in style.lower():
182+
mplhep.atlas.label(**kwargs)
183+
elif "cms" in style.lower():
184+
mplhep.cms.label(**kwargs)
185+
elif "lhcb" in style.lower():
186+
mplhep.lhcb.label(**kwargs)
187+
elif "dune" in style.lower():
188+
mplhep.dune.label(**kwargs)
189+
ax.legend()
190+
ax.set_xlabel("$m_{\mu\mu}$ [GeV]")
191+
ax.set_ylabel("Events")
192+
path = Path(
193+
here / f"_static/_generated/{style}/{histtype}/pos{position}.png"
194+
)
195+
path.parent.mkdir(parents=True, exist_ok=True)
196+
plt.savefig(path)
197+
plt.close()

docs/source/gallery/index.rst

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,3 @@ Gallery
77

88
styles
99
labels
10-
11-
.. jupyter-execute::
12-
:hide-code:
13-
:hide-output:
14-
15-
import matplotlib.pyplot as plt
16-
import mplhep
17-
import numpy as np
18-
from pathlib import Path
19-
import yaml
20-
21-
x = np.linspace(0, 10, 100)
22-
y = np.sin(x)
23-
24-
25-
26-
.. jupyter-execute::
27-
:hide-code:
28-
29-
# allstyle = [s for s in mplhep.style.__all__
30-
# if s != "use" and not s.lower().endswith("tex")
31-
# and "_" not in s
32-
# and s != "LHCb" # we want LHCb1 or LHCb2
33-
# ]
34-
# the upper one contains all possible styles, needed?
35-
allstyle = ["ATLAS1", "ATLAS2", "CMS", "LHCb1", "LHCb2", "ALICE"]
36-
allstyle = sorted(allstyle, key=lambda s: s.lower())
37-
# allstyle = sorted(allstyle, key=lambda s: s.lower().endswith("tex"))
38-
allstyle = sorted(allstyle, key=lambda s: s.lower().endswith("alt"))
39-
here = Path("__file__").parent.resolve() # jupyter workaround, use string
40-
41-
42-
with Path(here / '_static/bkg_sig_plot.yaml').resolve().open() as f:
43-
plotdata = yaml.load(f, Loader=yaml.FullLoader)
44-
for i, style in enumerate(allstyle):
45-
plt.style.use(getattr(mplhep.style, style))
46-
47-
plot = plotdata.copy()
48-
x = np.asarray(plot.pop('x'))
49-
data = tuple(plot.pop('Data'))
50-
for i, histtype in enumerate(['fill', 'step', 'errorbar', 'band']):
51-
for position in range(5):
52-
plt.figure()
53-
ax = plt.gca()
54-
title = f"{style} {histtype}"
55-
ax.set_title(title, y=1.02)
56-
mplhep.histplot(data, histtype=histtype, label='Data', ax=ax)
57-
for label, y in plot.items():
58-
ax.plot(x, np.asarray(y), label=label)
59-
60-
kwargs = dict(label="Preliminary", data=True, ax=ax, year=2016, loc=position, lumi=9)
61-
if "atlas" in style.lower():
62-
mplhep.atlas.label(**kwargs)
63-
elif "cms" in style.lower():
64-
mplhep.cms.label(**kwargs)
65-
elif "lhcb" in style.lower():
66-
mplhep.lhcb.label(**kwargs)
67-
ax.legend()
68-
ax.set_xlabel('$m_{\mu\mu}$ [GeV]')
69-
ax.set_ylabel('Events')
70-
path = Path(f"_static/_generated/{style}/{histtype}/pos{position}.png")
71-
path.parent.mkdir(parents=True, exist_ok=True)
72-
plt.savefig(path)
73-
plt.close()

docs/source/gallery/labels.rst

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,104 @@ label methods such as :py:func:`~mplhep.cms.label()` and the position argument `
1212
Position 0
1313
-------------------
1414

15-
.. image:: ../../_static/_generated/ATLAS/fill/pos0.png
15+
.. image:: ../_static/_generated/ATLAS/fill/pos0.png
1616
:width: 45%
1717

18-
.. image:: ../../_static/_generated/ATLASAlt/fill/pos0.png
18+
.. image:: ../_static/_generated/ATLASAlt/fill/pos0.png
1919
:width: 45%
2020

21-
.. image:: ../../_static/_generated/LHCb1/fill/pos0.png
21+
.. image:: ../_static/_generated/LHCb1/fill/pos0.png
2222
:width: 45%
2323

24-
.. image:: ../../_static/_generated/LHCb2/fill/pos0.png
24+
.. image:: ../_static/_generated/LHCb2/fill/pos0.png
2525
:width: 45%
2626

27-
.. image:: ../../_static/_generated/CMS/fill/pos0.png
27+
.. image:: ../_static/_generated/CMS/fill/pos0.png
28+
:width: 45%
29+
30+
.. image:: ../_static/_generated/DUNE/fill/pos0.png
2831
:width: 45%
2932

3033
Position 1
3134
-------------------
3235

33-
.. image:: ../../_static/_generated/ATLAS/fill/pos1.png
36+
.. image:: ../_static/_generated/ATLAS/fill/pos1.png
3437
:width: 45%
3538

36-
.. image:: ../../_static/_generated/ATLASAlt/fill/pos1.png
39+
.. image:: ../_static/_generated/ATLASAlt/fill/pos1.png
3740
:width: 45%
3841

39-
.. image:: ../../_static/_generated/LHCb1/fill/pos1.png
42+
.. image:: ../_static/_generated/LHCb1/fill/pos1.png
4043
:width: 45%
4144

42-
.. image:: ../../_static/_generated/LHCb2/fill/pos1.png
45+
.. image:: ../_static/_generated/LHCb2/fill/pos1.png
4346
:width: 45%
4447

45-
.. image:: ../../_static/_generated/CMS/fill/pos1.png
48+
.. image:: ../_static/_generated/CMS/fill/pos1.png
49+
:width: 45%
50+
51+
.. image:: ../_static/_generated/DUNE/fill/pos1.png
4652
:width: 45%
4753

4854
Position 2
4955
-------------------
5056

51-
.. image:: ../../_static/_generated/ATLAS/fill/pos2.png
57+
.. image:: ../_static/_generated/ATLAS/fill/pos2.png
58+
:width: 45%
59+
60+
.. image:: ../_static/_generated/ATLASAlt/fill/pos2.png
5261
:width: 45%
5362

54-
.. image:: ../../_static/_generated/ATLASAlt/fill/pos2.png
63+
.. image:: ../_static/_generated/LHCb1/fill/pos2.png
5564
:width: 45%
5665

57-
.. image:: ../../_static/_generated/LHCb1/fill/pos2.png
66+
.. image:: ../_static/_generated/LHCb2/fill/pos2.png
5867
:width: 45%
5968

60-
.. image:: ../../_static/_generated/LHCb2/fill/pos2.png
69+
.. image:: ../_static/_generated/CMS/fill/pos2.png
6170
:width: 45%
6271

63-
.. image:: ../../_static/_generated/CMS/fill/pos2.png
72+
.. image:: ../_static/_generated/DUNE/fill/pos2.png
6473
:width: 45%
6574

6675
Position 3
6776
-------------------
6877

69-
.. image:: ../../_static/_generated/ATLAS/fill/pos3.png
78+
.. image:: ../_static/_generated/ATLAS/fill/pos3.png
79+
:width: 45%
80+
81+
.. image:: ../_static/_generated/ATLASAlt/fill/pos3.png
7082
:width: 45%
7183

72-
.. image:: ../../_static/_generated/ATLASAlt/fill/pos3.png
84+
.. image:: ../_static/_generated/LHCb1/fill/pos3.png
7385
:width: 45%
7486

75-
.. image:: ../../_static/_generated/LHCb1/fill/pos3.png
87+
.. image:: ../_static/_generated/LHCb2/fill/pos3.png
7688
:width: 45%
7789

78-
.. image:: ../../_static/_generated/LHCb2/fill/pos3.png
90+
.. image:: ../_static/_generated/CMS/fill/pos3.png
7991
:width: 45%
8092

81-
.. image:: ../../_static/_generated/CMS/fill/pos3.png
93+
.. image:: ../_static/_generated/DUNE/fill/pos3.png
8294
:width: 45%
8395

8496
Position 4
8597
-------------------
8698

87-
.. image:: ../../_static/_generated/ATLAS/fill/pos4.png
99+
.. image:: ../_static/_generated/ATLAS/fill/pos4.png
100+
:width: 45%
101+
102+
.. image:: ../_static/_generated/ATLASAlt/fill/pos4.png
88103
:width: 45%
89104

90-
.. image:: ../../_static/_generated/ATLASAlt/fill/pos4.png
105+
.. image:: ../_static/_generated/LHCb1/fill/pos4.png
91106
:width: 45%
92107

93-
.. image:: ../../_static/_generated/LHCb1/fill/pos4.png
108+
.. image:: ../_static/_generated/LHCb2/fill/pos4.png
94109
:width: 45%
95110

96-
.. image:: ../../_static/_generated/LHCb2/fill/pos4.png
111+
.. image:: ../_static/_generated/CMS/fill/pos4.png
97112
:width: 45%
98113

99-
.. image:: ../../_static/_generated/CMS/fill/pos4.png
114+
.. image:: ../_static/_generated/DUNE/fill/pos4.png
100115
:width: 45%

0 commit comments

Comments
 (0)