@@ -401,6 +401,19 @@ def validate_fontsize(s):
401401validate_fontsizelist = _listify_validator (validate_fontsize )
402402
403403
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+
404417def validate_font_properties (s ):
405418 parse_fontconfig_pattern (s )
406419 return s
@@ -1095,7 +1108,7 @@ def _validate_linestyle(ls):
10951108 'font.style' : ['normal' , validate_string ],
10961109 'font.variant' : ['normal' , validate_string ],
10971110 'font.stretch' : ['normal' , validate_string ],
1098- 'font.weight' : ['normal' , validate_string ],
1111+ 'font.weight' : ['normal' , validate_fontweight ],
10991112 'font.size' : [10 , validate_float ], # Base font size in points
11001113 'font.serif' : [['DejaVu Serif' , 'Bitstream Vera Serif' ,
11011114 'Computer Modern Roman' ,
@@ -1174,7 +1187,7 @@ def _validate_linestyle(ls):
11741187 'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
11751188 # axes title
11761189 '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
11781191 'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
11791192 'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
11801193 'axes.grid' : [False , validate_bool ], # display grid or not
@@ -1187,7 +1200,7 @@ def _validate_linestyle(ls):
11871200 'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
11881201 # x any y labels
11891202 '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
11911204 'axes.labelcolor' : ['black' , validate_color ], # color of axis label
11921205 'axes.formatter.limits' : [[- 5 , 6 ], validate_nseq_int (2 )],
11931206 # use scientific notation if log10
@@ -1320,7 +1333,7 @@ def _validate_linestyle(ls):
13201333 ## figure props
13211334 # figure title
13221335 'figure.titlesize' : ['large' , validate_fontsize ],
1323- 'figure.titleweight' : ['normal' , validate_string ],
1336+ 'figure.titleweight' : ['normal' , validate_fontweight ],
13241337
13251338 # figure size in inches: width by height
13261339 'figure.figsize' : [[6.4 , 4.8 ], validate_nseq_float (2 )],
0 commit comments