@@ -634,6 +634,7 @@ def validate_sketch(s):
634634 return result
635635
636636
637+ @cbook .deprecated ("3.1" )
637638class ValidateInterval :
638639 """
639640 Value must be in interval
@@ -666,6 +667,28 @@ def __call__(self, s):
666667 return s
667668
668669
670+ def _validate_greaterequal0_lessthan1 (s ):
671+ s = validate_float (s )
672+ if 0 <= s < 1 :
673+ return s
674+ else :
675+ raise RuntimeError (f'Value must be >=0 and <1; got { s } ' )
676+
677+
678+ def _validate_greaterequal0_lessequal1 (s ):
679+ s = validate_float (s )
680+ if 0 <= s <= 1 :
681+ return s
682+ else :
683+ raise RuntimeError (f'Value must be >=0 and <=1; got { s } ' )
684+
685+
686+ _range_validators = { # Slightly nicer (internal) API.
687+ "0 <= x < 1" : _validate_greaterequal0_lessthan1 ,
688+ "0 <= x <= 1" : _validate_greaterequal0_lessequal1 ,
689+ }
690+
691+
669692validate_grid_axis = ValidateInStrings ('axes.grid.axis' , ['x' , 'y' , 'both' ])
670693
671694
@@ -1176,15 +1199,10 @@ def _validate_linestyle(ls):
11761199 'axes.autolimit_mode' : [
11771200 'data' ,
11781201 ValidateInStrings ('autolimit_mode' , ['data' , 'round_numbers' ])],
1179- 'axes.xmargin' : [0.05 , ValidateInterval (0 , 1 ,
1180- closedmin = True ,
1181- closedmax = True )], # margin added to xaxis
1182- 'axes.ymargin' : [0.05 , ValidateInterval (0 , 1 ,
1183- closedmin = True ,
1184- closedmax = True )], # margin added to yaxis
1185-
1186- 'polaraxes.grid' : [True , validate_bool ], # display polar grid or
1187- # not
1202+ 'axes.xmargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1203+ 'axes.ymargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1204+
1205+ 'polaraxes.grid' : [True , validate_bool ], # display polar grid or not
11881206 'axes3d.grid' : [True , validate_bool ], # display 3d grid
11891207
11901208 # scatter props
@@ -1298,28 +1316,22 @@ def _validate_linestyle(ls):
12981316 'figure.autolayout' : [False , validate_bool ],
12991317 'figure.max_open_warning' : [20 , validate_int ],
13001318
1301- 'figure.subplot.left' : [0.125 , ValidateInterval (0 , 1 , closedmin = True ,
1302- closedmax = True )],
1303- 'figure.subplot.right' : [0.9 , ValidateInterval (0 , 1 , closedmin = True ,
1304- closedmax = True )],
1305- 'figure.subplot.bottom' : [0.11 , ValidateInterval (0 , 1 , closedmin = True ,
1306- closedmax = True )],
1307- 'figure.subplot.top' : [0.88 , ValidateInterval (0 , 1 , closedmin = True ,
1308- closedmax = True )],
1309- 'figure.subplot.wspace' : [0.2 , ValidateInterval (0 , 1 , closedmin = True ,
1310- closedmax = False )],
1311- 'figure.subplot.hspace' : [0.2 , ValidateInterval (0 , 1 , closedmin = True ,
1312- closedmax = False )],
1319+ 'figure.subplot.left' : [0.125 , _range_validators ["0 <= x <= 1" ]],
1320+ 'figure.subplot.right' : [0.9 , _range_validators ["0 <= x <= 1" ]],
1321+ 'figure.subplot.bottom' : [0.11 , _range_validators ["0 <= x <= 1" ]],
1322+ 'figure.subplot.top' : [0.88 , _range_validators ["0 <= x <= 1" ]],
1323+ 'figure.subplot.wspace' : [0.2 , _range_validators ["0 <= x < 1" ]],
1324+ 'figure.subplot.hspace' : [0.2 , _range_validators ["0 <= x < 1" ]],
13131325
13141326 # do constrained_layout.
13151327 'figure.constrained_layout.use' : [False , validate_bool ],
13161328 # wspace and hspace are fraction of adjacent subplots to use
13171329 # for space. Much smaller than above because we don't need
13181330 # room for the text.
1319- 'figure.constrained_layout.hspace' : [ 0.02 , ValidateInterval (
1320- 0 , 1 , closedmin = True , closedmax = False ) ],
1321- 'figure.constrained_layout.wspace' : [ 0.02 , ValidateInterval (
1322- 0 , 1 , closedmin = True , closedmax = False ) ],
1331+ 'figure.constrained_layout.hspace' :
1332+ [ 0.02 , _range_validators [ "0 <= x < 1" ] ],
1333+ 'figure.constrained_layout.wspace' :
1334+ [ 0.02 , _range_validators [ "0 <= x < 1" ] ],
13231335 # This is a buffer around the axes in inches. This is 3pts.
13241336 'figure.constrained_layout.h_pad' : [0.04167 , validate_float ],
13251337 'figure.constrained_layout.w_pad' : [0.04167 , validate_float ],
@@ -1376,7 +1388,7 @@ def _validate_linestyle(ls):
13761388 'docstring.hardcopy' : [False , validate_bool ],
13771389
13781390 'path.simplify' : [True , validate_bool ],
1379- 'path.simplify_threshold' : [1.0 / 9.0 , ValidateInterval ( 0.0 , 1.0 ) ],
1391+ 'path.simplify_threshold' : [1 / 9 , _range_validators [ "0 <= x <= 1" ] ],
13801392 'path.snap' : [True , validate_bool ],
13811393 'path.sketch' : [None , validate_sketch ],
13821394 'path.effects' : [[], validate_any ],
0 commit comments