From 12533d857fa994b64399ac52e350e24f5c50fdd8 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 10 May 2023 00:00:21 +0200 Subject: [PATCH] Fix invalid range validators. - The correct bound on margins value, documented in set_x/y/zmargin, is margin>-0.5. Fix the docstring of margins() and the rc validators. - The only constraints on tight/constrained layout margins is left -0.5: return s else: - raise RuntimeError(f'Value must be >=0 and <1; got {s}') + raise RuntimeError(f'Value must be >-0.5; got {s}') def _validate_greaterequal0_lessequal1(s): @@ -568,12 +568,6 @@ def _validate_greaterequal0_lessequal1(s): raise RuntimeError(f'Value must be >=0 and <=1; got {s}') -_range_validators = { # Slightly nicer (internal) API. - "0 <= x < 1": _validate_greaterequal0_lessthan1, - "0 <= x <= 1": _validate_greaterequal0_lessequal1, -} - - def validate_hatch(s): r""" Validate a hatch pattern. @@ -1012,9 +1006,9 @@ def _convert_validator_spec(key, conv): # If "data", axes limits are set close to the data. # If "round_numbers" axes limits are set to the nearest round numbers. "axes.autolimit_mode": ["data", "round_numbers"], - "axes.xmargin": _range_validators["0 <= x <= 1"], # margin added to xaxis - "axes.ymargin": _range_validators["0 <= x <= 1"], # margin added to yaxis - 'axes.zmargin': _range_validators["0 <= x <= 1"], # margin added to zaxis + "axes.xmargin": _validate_greaterthan_minushalf, # margin added to xaxis + "axes.ymargin": _validate_greaterthan_minushalf, # margin added to yaxis + "axes.zmargin": _validate_greaterthan_minushalf, # margin added to zaxis "polaraxes.grid": validate_bool, # display polar grid or not "axes3d.grid": validate_bool, # display 3d grid @@ -1149,21 +1143,21 @@ def _convert_validator_spec(key, conv): "figure.max_open_warning": validate_int, "figure.raise_window": validate_bool, - "figure.subplot.left": _range_validators["0 <= x <= 1"], - "figure.subplot.right": _range_validators["0 <= x <= 1"], - "figure.subplot.bottom": _range_validators["0 <= x <= 1"], - "figure.subplot.top": _range_validators["0 <= x <= 1"], - "figure.subplot.wspace": _range_validators["0 <= x < 1"], - "figure.subplot.hspace": _range_validators["0 <= x < 1"], + "figure.subplot.left": validate_float, + "figure.subplot.right": validate_float, + "figure.subplot.bottom": validate_float, + "figure.subplot.top": validate_float, + "figure.subplot.wspace": validate_float, + "figure.subplot.hspace": validate_float, "figure.constrained_layout.use": validate_bool, # run constrained_layout? # wspace and hspace are fraction of adjacent subplots to use for space. # Much smaller than above because we don't need room for the text. - "figure.constrained_layout.hspace": _range_validators["0 <= x < 1"], - "figure.constrained_layout.wspace": _range_validators["0 <= x < 1"], + "figure.constrained_layout.hspace": validate_float, + "figure.constrained_layout.wspace": validate_float, # buffer around the axes, in inches. - 'figure.constrained_layout.h_pad': validate_float, - 'figure.constrained_layout.w_pad': validate_float, + "figure.constrained_layout.h_pad": validate_float, + "figure.constrained_layout.w_pad": validate_float, ## Saving figure's properties 'savefig.dpi': validate_dpi, @@ -1207,7 +1201,7 @@ def _convert_validator_spec(key, conv): "docstring.hardcopy": validate_bool, "path.simplify": validate_bool, - "path.simplify_threshold": _range_validators["0 <= x <= 1"], + "path.simplify_threshold": _validate_greaterequal0_lessequal1, "path.snap": validate_bool, "path.sketch": validate_sketch, "path.effects": validate_anylist,