@@ -401,6 +401,19 @@ def validate_fontsize(s):
401
401
validate_fontsizelist = _listify_validator (validate_fontsize )
402
402
403
403
404
+ def validate_fontweight (s ):
405
+ weights = [
406
+ 'ultralight' , 'light' , 'normal' , 'regular' , 'book' , 'medium' , 'roman' ,
407
+ 'semibold' , 'demibold' , 'demi' , 'bold' , 'heavy' , 'extra bold' , 'black' ]
408
+ # Note: Historically, weights have been case-sensitive in Matplotlib
409
+ if s in weights :
410
+ return s
411
+ try :
412
+ return int (s )
413
+ except (ValueError , TypeError ):
414
+ raise ValueError (f'{ s } is not a valid font weight. %s' )
415
+
416
+
404
417
def validate_font_properties (s ):
405
418
parse_fontconfig_pattern (s )
406
419
return s
@@ -1095,7 +1108,7 @@ def _validate_linestyle(ls):
1095
1108
'font.style' : ['normal' , validate_string ],
1096
1109
'font.variant' : ['normal' , validate_string ],
1097
1110
'font.stretch' : ['normal' , validate_string ],
1098
- 'font.weight' : ['normal' , validate_string ],
1111
+ 'font.weight' : ['normal' , validate_fontweight ],
1099
1112
'font.size' : [10 , validate_float ], # Base font size in points
1100
1113
'font.serif' : [['DejaVu Serif' , 'Bitstream Vera Serif' ,
1101
1114
'Computer Modern Roman' ,
@@ -1174,7 +1187,7 @@ def _validate_linestyle(ls):
1174
1187
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1175
1188
# axes title
1176
1189
'axes.titlelocation' : ['center' , validate_axes_titlelocation ], # alignment of axes title
1177
- 'axes.titleweight' : ['normal' , validate_string ], # font weight of axes title
1190
+ 'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
1178
1191
'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
1179
1192
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1180
1193
'axes.grid' : [False , validate_bool ], # display grid or not
@@ -1187,7 +1200,7 @@ def _validate_linestyle(ls):
1187
1200
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1188
1201
# x any y labels
1189
1202
'axes.labelpad' : [4.0 , validate_float ], # space between label and axis
1190
- 'axes.labelweight' : ['normal' , validate_string ], # fontsize of the x any y labels
1203
+ 'axes.labelweight' : ['normal' , validate_fontweight ], # fontsize of the x any y labels
1191
1204
'axes.labelcolor' : ['black' , validate_color ], # color of axis label
1192
1205
'axes.formatter.limits' : [[- 5 , 6 ], validate_nseq_int (2 )],
1193
1206
# use scientific notation if log10
@@ -1320,7 +1333,7 @@ def _validate_linestyle(ls):
1320
1333
## figure props
1321
1334
# figure title
1322
1335
'figure.titlesize' : ['large' , validate_fontsize ],
1323
- 'figure.titleweight' : ['normal' , validate_string ],
1336
+ 'figure.titleweight' : ['normal' , validate_fontweight ],
1324
1337
1325
1338
# figure size in inches: width by height
1326
1339
'figure.figsize' : [[6.4 , 4.8 ], validate_nseq_float (2 )],
0 commit comments