@@ -236,6 +236,20 @@ def validate_fonttype(s):
236
236
return fonttype
237
237
238
238
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
+
239
253
_validate_standard_backends = ValidateInStrings (
240
254
'backend' , all_backends , ignorecase = True )
241
255
_auto_backend_sentinel = object ()
@@ -1095,7 +1109,7 @@ def _validate_linestyle(ls):
1095
1109
'font.style' : ['normal' , validate_string ],
1096
1110
'font.variant' : ['normal' , validate_string ],
1097
1111
'font.stretch' : ['normal' , validate_string ],
1098
- 'font.weight' : ['normal' , validate_string ],
1112
+ 'font.weight' : ['normal' , validate_fontweight ],
1099
1113
'font.size' : [10 , validate_float ], # Base font size in points
1100
1114
'font.serif' : [['DejaVu Serif' , 'Bitstream Vera Serif' ,
1101
1115
'Computer Modern Roman' ,
@@ -1174,7 +1188,7 @@ def _validate_linestyle(ls):
1174
1188
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1175
1189
# axes title
1176
1190
'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
1178
1192
'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
1179
1193
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1180
1194
'axes.grid' : [False , validate_bool ], # display grid or not
@@ -1187,7 +1201,7 @@ def _validate_linestyle(ls):
1187
1201
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1188
1202
# x any y labels
1189
1203
'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
1191
1205
'axes.labelcolor' : ['black' , validate_color ], # color of axis label
1192
1206
'axes.formatter.limits' : [[- 5 , 6 ], validate_nseq_int (2 )],
1193
1207
# use scientific notation if log10
@@ -1320,7 +1334,7 @@ def _validate_linestyle(ls):
1320
1334
## figure props
1321
1335
# figure title
1322
1336
'figure.titlesize' : ['large' , validate_fontsize ],
1323
- 'figure.titleweight' : ['normal' , validate_string ],
1337
+ 'figure.titleweight' : ['normal' , validate_fontweight ],
1324
1338
1325
1339
# figure size in inches: width by height
1326
1340
'figure.figsize' : [[6.4 , 4.8 ], validate_nseq_float (2 )],
0 commit comments