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

Skip to content

Commit 9bbde2a

Browse files
committed
Validate locator_params(axis=...)
1 parent 01b5833 commit 9bbde2a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Behaviour changes
55
~~~~~~~~~~~~~~~~~~~~~~~
66
`.Formatter.fix_minus` now performs hyphen-to-unicode-minus replacement
77
whenever :rc:`axes.unicode_minus` is True; i.e. its behavior matches the one
8-
of ``.ScalarFormatter.fix_minus`` (`.ScalarFormatter` now just inherits that
8+
of ``ScalarFormatter.fix_minus`` (`.ScalarFormatter` now just inherits that
99
implementation).
1010

1111
This replacement is now used by the ``format_data_short`` method of the various
@@ -25,3 +25,8 @@ callbacks when no interactive GUI event loop is running. If a GUI event loop
2525
*is* running, `.cbook.CallbackRegistry` still defaults to just printing a
2626
traceback, as unhandled exceptions can make the program completely ``abort()``
2727
in that case.
28+
29+
``Axes.locator_params()`` validates ``axis`` parameter
30+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
`.axes.Axes.locator_params` used to accept any value for ``axis`` and silently
32+
did nothing, when passed an unsupported value. It now raises a ``ValueError``.

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,7 @@ def locator_params(self, axis='both', tight=None, **kwargs):
29122912
29132913
Parameters
29142914
----------
2915-
axis : {'both', 'x', 'y'}, optional
2915+
axis : {'both', 'x', 'y'}, default: 'both'
29162916
The axis on which to operate.
29172917
29182918
tight : bool or None, optional
@@ -2936,13 +2936,15 @@ def locator_params(self, axis='both', tight=None, **kwargs):
29362936
ax.locator_params(tight=True, nbins=4)
29372937
29382938
"""
2939-
_x = axis in ['x', 'both']
2940-
_y = axis in ['y', 'both']
2941-
if _x:
2939+
cbook._check_in_list(['x', 'y', 'both'], axis=axis)
2940+
update_x = axis in ['x', 'both']
2941+
update_y = axis in ['y', 'both']
2942+
if update_x:
29422943
self.xaxis.get_major_locator().set_params(**kwargs)
2943-
if _y:
2944+
if update_y:
29442945
self.yaxis.get_major_locator().set_params(**kwargs)
2945-
self._request_autoscale_view(tight=tight, scalex=_x, scaley=_y)
2946+
self._request_autoscale_view(tight=tight,
2947+
scalex=update_x, scaley=update_y)
29462948

29472949
def tick_params(self, axis='both', **kwargs):
29482950
"""Change the appearance of ticks, tick labels, and gridlines.

0 commit comments

Comments
 (0)