diff --git a/lib/matplotlib/_constrained_layout.py b/lib/matplotlib/_constrained_layout.py index fc09a407a36a..659506360c00 100644 --- a/lib/matplotlib/_constrained_layout.py +++ b/lib/matplotlib/_constrained_layout.py @@ -678,7 +678,7 @@ def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None): width and height padding (in fraction of figure) hspace, wspace : float width and height padding as fraction of figure size divided by - number of columns or rows + number of columns or rows margin : array-like offset the colorbar needs to be pushed to in order to account for multiple colorbars diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 2c3d93fa8d8d..e6f0c178fb1d 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2665,10 +2665,10 @@ def margins(self, *margins, x=None, y=None, tight=True): The padding added to each limit of the Axes is the *margin* times the data interval. All input parameters must be floats - within the range [0, 1]. Passing both positional and keyword + greater than -0.5. Passing both positional and keyword arguments is invalid and will raise a TypeError. If no arguments (positional or otherwise) are provided, the current - margins will remain in place and simply be returned. + margins will remain unchanged and simply be returned. Specifying any margin changes only the autoscaling; for example, if *xmargin* is not None, then *xmargin* times the X data diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index a5e36cba22cc..578777167d6c 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -585,10 +585,14 @@ #figure.constrained_layout.use: False # When True, automatically make plot # elements fit on the figure. (Not # compatible with `autolayout`, above). -#figure.constrained_layout.h_pad: 0.04167 # Padding around axes objects. Float representing -#figure.constrained_layout.w_pad: 0.04167 # inches. Default is 3/72 inches (3 points) -#figure.constrained_layout.hspace: 0.02 # Space between subplot groups. Float representing -#figure.constrained_layout.wspace: 0.02 # a fraction of the subplot widths being separated. +## Padding (in inches) around axes; defaults to 3/72 inches, i.e. 3 points. +#figure.constrained_layout.h_pad: 0.04167 +#figure.constrained_layout.w_pad: 0.04167 +## Spacing between subplots, relative to the subplot sizes. Much smaller than for +## tight_layout (figure.subplot.hspace, figure.subplot.wspace) as constrained_layout +## already takes surrounding texts (titles, labels, # ticklabels) into account. +#figure.constrained_layout.hspace: 0.02 +#figure.constrained_layout.wspace: 0.02 ## *************************************************************************** diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a9bebd209077..8e5c7dd9941c 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -552,12 +552,12 @@ def validate_sketch(s): raise ValueError("Expected a (scale, length, randomness) triplet") -def _validate_greaterequal0_lessthan1(s): +def _validate_greaterthan_minushalf(s): s = validate_float(s) - if 0 <= s < 1: + if s > -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,