8000 Fix font weight validation · matplotlib/matplotlib@29b6780 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29b6780

Browse files
committed
Fix font weight validation
1 parent bb7e441 commit 29b6780

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ def validate_fonttype(s):
236236
return fonttype
237237

238238

239+
def validate_fontweight(s):
240+
"""Validate that *s* is a font weight, i.e. either an int or a string.
241+
"""
242+
if isinstance(s, str):
243+
try:
244+
return int(s)
245+
except ValueError:
246+
return s
247+
elif isinstance(s, numbers.Number): # also numpy ints
248+
return s
249+
else:
250+
raise ValueError(f'{s} is not a valid font weight.')
251+
252+
239253
_validate_standard_backends = ValidateInStrings(
240254
'backend', all_backends, ignorecase=True)
241255
_auto_backend_sentinel = object()
@@ -1095,7 +1109,7 @@ def _validate_linestyle(ls):
10951109
'font.style': ['normal', validate_string],
10961110
'font.variant': ['normal', validate_string],
10971111
'font.stretch': ['normal', validate_string],
1098-
'font.weight': ['normal', validate_string],
1112+
'font.weight': ['normal', validate_fontweight],
10991113
'font.size': [10, validate_float], # Base font size in points
11001114
'font.serif': [['DejaVu Serif', 'Bitstream Vera Serif',
11011115
'Computer Modern Roman',
@@ -1174,7 +1188,7 @@ def _validate_linestyle(ls):
11741188
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
11751189
# axes title
11761190
'axes.titlelocation': ['center', validate_axes_titlelocation], # alignment of axes title
1177-
'axes.titleweight': ['normal', validate_string], # font weight of axes title
1191+
'axes.titleweight': ['normal', validate_fontweight], # font weight of axes title
11781192
'axes.titlecolor': ['auto', validate_color_or_auto], # font color of axes title
11791193
'axes.titlepad': [6.0, validate_float], # pad from axes top to title in points
11801194
'axes.grid': [False, validate_bool], # display grid or not
@@ -1187,7 +1201,7 @@ def _validate_linestyle(ls):
11871201
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
11881202
# x any y labels
11891203
'axes.labelpad': [4.0, validate_float], # space between label and axis
1190-
'axes.labelweight': ['normal', validate_string], # fontsize of the x any y labels
1204+
'axes.labelweight': ['normal', validate_fontweight], # fontsize of the x any y labels
11911205
'axes.labelcolor': ['black', validate_color], # color of axis label
11921206
'axes.formatter.limits': [[-5, 6], validate_nseq_int(2)],
11931207
# use scientific notation if log10
@@ -1320,7 +1334,7 @@ def _validate_linestyle(ls):
13201334
## figure props
13211335
# figure title
13221336
'figure.titlesize': ['large', validate_fontsize],
1323-
'figure.titleweight': ['normal', validate_string],
1337+
'figure.titleweight': ['normal', validate_fontweight],
13241338

13251339
# figure size in inches: width by height
13261340
'figure.figsize': [[6.4, 4.8], validate_nseq_float(2)],

0 commit comments

Comments
 (0)
0