|
9 | 9 | # -- Path setup -------------------------------------------------------------- |
10 | 10 | import importlib |
11 | 11 | 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 | | -# |
17 | 12 | import os |
18 | 13 | import subprocess |
19 | 14 | import sys |
20 | 15 | 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 |
21 | 23 |
|
| 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 | +# |
22 | 28 | # Add mplhep to path for sphinx-automodapi |
23 | 29 | sys.path.insert(0, os.path.abspath("../../src")) |
24 | 30 |
|
25 | | -from pathlib import Path |
26 | | - |
27 | | -import mplhep |
28 | 31 |
|
29 | 32 | # -- Project information ----------------------------------------------------- |
30 | 33 |
|
@@ -83,10 +86,10 @@ def linkcode_resolve(domain, info): |
83 | 86 |
|
84 | 87 |
|
85 | 88 | 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 |
90 | 93 | } |
91 | 94 |
|
92 | 95 | # The master toctree document. |
@@ -133,3 +136,62 @@ def linkcode_resolve(domain, info): |
133 | 136 | # so a file named "default.css" will overwrite the builtin "default.css". |
134 | 137 |
|
135 | 138 | 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() |
0 commit comments