@@ -461,6 +461,19 @@ def validate_fontsize(s):
461461validate_fontsizelist = _listify_validator (validate_fontsize )
462462
463463
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+
464477def validate_font_properties (s ):
465478 parse_fontconfig_pattern (s )
466479 return s
@@ -1113,7 +1126,7 @@ def _validate_linestyle(ls):
11131126 'font.style' : ['normal' , validate_string ],
11141127 'font.variant' : ['normal' , validate_string ],
11151128 'font.stretch' : ['normal' , validate_string ],
1116- 'font.weight' : ['normal' , validate_string ],
1129+ 'font.weight' : ['normal' , validate_fontweight ],
11171130 'font.size' : [10 , validate_float ], # Base font size in points
11181131 'font.serif' : [['DejaVu Serif' , 'Bitstream Vera Serif' ,
11191132 'Computer Modern Roman' ,
@@ -1190,7 +1203,7 @@ def _validate_linestyle(ls):
11901203
11911204 'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
11921205 # axes title
1193- 'axes.titleweight' : ['normal' , validate_string ], # font weight of axes title
1206+ 'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
11941207 'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
11951208 'axes.grid' : [False , validate_bool ], # display grid or not
11961209 'axes.grid.which' : ['major' , validate_axis_locator ], # set whether the gid are by
@@ -1202,7 +1215,7 @@ def _validate_linestyle(ls):
12021215 'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
12031216 # x any y labels
12041217 'axes.labelpad' : [4.0 , validate_float ], # space between label and axis
1205- 'axes.labelweight' : ['normal' , validate_string ], # fontsize of the x any y labels
1218+ 'axes.labelweight' : ['normal' , validate_fontweight ], # fontsize of the x any y labels
12061219 'axes.labelcolor' : ['black' , validate_color ], # color of axis label
12071220 'axes.formatter.limits' : [[- 7 , 7 ], validate_nseq_int (2 )],
12081221 # use scientific notation if log10
@@ -1340,7 +1353,7 @@ def _validate_linestyle(ls):
13401353 ## figure props
13411354 # figure title
13421355 'figure.titlesize' : ['large' , validate_fontsize ],
1343- 'figure.titleweight' : ['normal' , validate_string ],
1356+ 'figure.titleweight' : ['normal' , validate_fontweight ],
13441357
13451358 # figure size in inches: width by height
13461359 'figure.figsize' : [[6.4 , 4.8 ], validate_nseq_float (2 )],
0 commit comments