Skip to content

Commit 7147025

Browse files
fix: lumittext for LHCb to use the right font (#587)
* fix: lumittext for LHCb to use the right font * fix: ruff * chore: flake * fix: errorbreaks * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4e078c1 commit 7147025

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

src/mplhep/lhcb.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
from mplhep import label as label_base
2626

2727
from ._compat import docstring
28-
from .label import lumitext
28+
from .label import lumitext as _base_lumitext
2929
from .styles import lhcb as style
3030

31-
__all__ = ("label", "lumitext", "style", "text")
31+
__all__ = ("label", "_base_lumitext", "style", "text")
3232

3333

3434
@docstring.copy(label_base.exp_text)
@@ -66,3 +66,20 @@ def label(label=None, **kwargs):
6666
if label is not None:
6767
kwargs["label"] = label
6868
return label_base.exp_label("LHCb", **kwargs)
69+
70+
71+
@docstring.copy(label_base.lumitext)
72+
def lumitext(text="", **kwargs):
73+
for key, value in dict(mplhep.rcParams.text._get_kwargs()).items():
74+
if (
75+
value is not None
76+
and key not in kwargs
77+
and key in inspect.getfullargspec(label_base.lumitext).kwonlyargs
78+
):
79+
kwargs.setdefault(key, value)
80+
# kwargs.setdefault("italic", (False, False, False))
81+
# kwargs.setdefault("fontsize", 28)
82+
kwargs.setdefault("fontname", "Times New Roman")
83+
# kwargs.setdefault("loc", 1)
84+
# kwargs.setdefault("exp_weight", "normal")
85+
return label_base.lumitext("LHCb", text=text, **kwargs)

src/mplhep/styles/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@
4444
)
4545

4646

47+
__style_aliases__ = (
48+
"ALICE",
49+
"ATLAS",
50+
"CMS",
51+
"PLOTHIST",
52+
"ROOT",
53+
"ATLAS1",
54+
"ATLAS2",
55+
"ATLASAlt",
56+
"ATLASTex",
57+
"CMSTex",
58+
"DUNE1",
59+
"DUNETex1",
60+
"DUNE",
61+
"DUNETex",
62+
"LHCb",
63+
"LHCb1",
64+
"LHCb2",
65+
"LHCbTex",
66+
"LHCbTex1",
67+
"LHCbTex2",
68+
"ROOTTex",
69+
"fabiola",
70+
"fira",
71+
"firamath",
72+
)
73+
74+
4775
@deprecate.deprecate(
4876
"Naming convention is changing to match mpl. Use ``mplhep.style.use()``."
4977
)
@@ -75,6 +103,19 @@ def use(styles=None):
75103
styles = [styles]
76104

77105
# passed in experiment mplhep.style dict or str alias
106+
_passed_aliases = [style for style in styles if not isinstance(style, dict)]
107+
if len(_passed_aliases) > 1:
108+
error_msg = (
109+
'Can only pass in one style alias at a time, but can modify settings eg. `use(["CMS", {"font.size":25}])`. '
110+
f"Got {', '.join(_passed_aliases)}"
111+
)
112+
raise ValueError(error_msg)
113+
if (
114+
len(_passed_aliases) == 1
115+
and _passed_aliases[0] not in sys.modules[__name__].__dict__
116+
):
117+
error_msg = f"Unknown style alias: {_passed_aliases[0]}. Choose from {list(__style_aliases__)}"
118+
raise ValueError(error_msg)
78119
styles = [
79120
style if isinstance(style, dict) else getattr(sys.modules[__name__], f"{style}")
80121
for style in styles

0 commit comments

Comments
 (0)