8000 Merge pull request #30030 from founta/sans-serif-alias · matplotlib/matplotlib@24bcabb · GitHub
[go: up one dir, main page]

Skip to content

Commit 24bcabb

Browse files
authored
Merge pull request #30030 from founta/sans-serif-alias
Add "sans" alias to rc() to allow users to set font.sans-serif
2 parents 8cd97bf + fd687a9 commit 24bcabb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,17 +995,18 @@ def rc(group, **kwargs):
995995
996996
The following aliases are available to save typing for interactive users:
997997
998-
===== =================
998+
====== =================
999999
Alias Property
1000-
===== =================
1000+
====== =================
10011001
'lw' 'linewidth'
10021002
'ls' 'linestyle'
10031003
'c' 'color'
10041004
'fc' 'facecolor'
10051005
'ec' 'edgecolor'
10061006
'mew' 'markeredgewidth'
10071007
'aa' 'antialiased'
1008-
===== =================
1008+
'sans' 'sans-serif'
1009+
====== =================
10091010
10101011
Thus you could abbreviate the above call as::
10111012
@@ -1039,6 +1040,7 @@ def rc(group, **kwargs):
10391040
'ec': 'edgecolor',
10401041
'mew': 'markeredgewidth',
10411042
'aa': 'antialiased',
1043+
'sans': 'sans-serif',
10421044
}
10431045

10441046
if isinstance(group, str):

lib/matplotlib/tests/test_rcparams.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,21 @@ def test_rcparams_path_sketch_from_file(tmp_path, value):
654654
rc_path.write_text(f"path.sketch: {value}")
655655
with mpl.rc_context(fname=rc_path):
656656
assert mpl.rcParams["path.sketch"] == (1, 2, 3)
657+
658+
659+
@pytest.mark.parametrize('group, option, alias, value', [
660+
('lines', 'linewidth', 'lw', 3),
661+
('lines', 'linestyle', 'ls', 'dashed'),
662+
('lines', 'color', 'c', 'white'),
663+
('axes', 'facecolor', 'fc', 'black'),
664+
('figure', 'edgecolor', 'ec', 'magenta'),
665+
('lines', 'markeredgewidth', 'mew', 1.5),
666+
('patch', 'antialiased', 'aa', False),
667+
('font', 'sans-serif', 'sans', ["Verdana"])
668+
])
669+
def test_rc_aliases(group, option, alias, value):
670+
rc_kwargs = {alias: value,}
671+
mpl.rc(group, **rc_kwargs)
672+
673+
rcParams_key = f"{group}.{option}"
674+
assert mpl.rcParams[rcParams_key] == value

0 commit comments

Comments
 (0)
0