Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix invalid range validators. #25843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -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


## ***************************************************************************
Expand Down
40 changes: 17 additions & 23 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down