@@ -461,6 +461,19 @@ def validate_fontsize(s):
461
461
validate_fontsizelist = _listify_validator (validate_fontsize )
462
462
463
463
464
+ def validate_fontweight (s ):
465
+ weights = [
466
+ 'ultralight' , 'light' , 'normal' , 'regular' , 'book' , 'medium' , 'roman' ,
467
+ 'semibold' , 'demibold' , 'demi' , 'bold' , 'heavy' , 'extra bold' , 'black' ]
468
+ # Note: Historically, weights have been case-sensitive in Matplotlib
469
+ if s in weights :
470
+ return s
471
+ try :
472
+ return int (s )
473
+ except (ValueError , TypeError ):
474
+ raise ValueError (f'{ s } is not a valid font weight. %s' )
475
+
476
+
464
477
def validate_font_properties (s ):
465
478
parse_fontconfig_pattern (s )
466
479
return s
@@ -1113,7 +1126,7 @@ def _validate_linestyle(ls):
1113
1126
'font.style' : ['normal' , validate_string ],
1114
1127
'font.variant' : ['normal' , validate_string ],
1115
1128
'font.stretch' : ['normal' , validate_string ],
1116
- 'font.weight' : ['normal' , validate_string ],
1129
+ 'font.weight' : ['normal' , validate_fontweight ],
1117
1130
'font.size' : [10 , validate_float ], # Base font size in points
1118
1131
'font.serif' : [['DejaVu Serif' , 'Bitstream Vera Serif' ,
1119
1132
'Computer Modern Roman' ,
@@ -1190,7 +1203,7 @@ def _validate_linestyle(ls):
1190
1203
1191
1204
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1192
1205
# axes title
1193
- 'axes.titleweight' : ['normal' , validate_string ], # font weight of axes title
1206
+ 'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
1194
1207
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1195
1208
'axes.grid' : [False , validate_bool ], # display grid or not
1196
1209
'axes.grid.which' : ['major' , validate_axis_locator ], # set whether the gid are by
@@ -1202,7 +1215,7 @@ def _validate_linestyle(ls):
1202
1215
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1203
1216
# x any y labels
1204
1217
'axes.labelpad' : [4.0 , validate_float ], # space between label and axis
1205
- 'axes.labelweight' : ['normal' , validate_string ], # fontsize of the x any y labels
<
8000
/tr>
1218
+ 'axes.labelweight' : ['normal' , validate_fontweight ], # fontsize of the x any y labels
1206
1219
'axes.labelcolor' : ['black' , validate_color ], # color of axis label
1207
1220
'axes.formatter.limits' : [[- 7 , 7 ], validate_nseq_int (2 )],
1208
1221
# use scientific notation if log10
@@ -1340,7 +1353,7 @@ def _validate_linestyle(ls):
1340
1353
## figure props
1341
1354
# figure title
1342
1355
'figure.titlesize' : ['large' , validate_fontsize ],
1343
- 'figure.titleweight' : ['normal' , validate_string ],
1356
+ 'figure.titleweight' : ['normal' , validate_fontweight ],
1344
1357
1345
1358
# figure size in inches: width by height
1346
1359
'figure.figsize' : [[6.4 , 4.8 ], validate_nseq_float (2 )],
0 commit comments