Skip to content

Commit ec47e76

Browse files
committed
Validate set_tick_params(which=...)
1 parent 349e2e9 commit ec47e76

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ in that case.
3030
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3131
`.axes.Axes.locator_params` used to accept any value for ``axis`` and silently
3232
did nothing, when passed an unsupported value. It now raises a ``ValueError``.
33+
34+
``Axis.set_tick_params()`` validates ``which`` parameter
35+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36+
`.Axis.set_tick_params` (and the higher level `.axes.Axes.tick_params` and
37+
`.pyplot.tick_params`) used to accept any value for ``which`` and silently
38+
did nothing, when passed an unsupported value. It now raises a ``ValueError``.

lib/matplotlib/axis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,10 @@ def set_tick_params(self, which='major', reset=False, **kw):
889889
:meth:`matplotlib.axes.Axes.tick_params`.
890890
"""
891891
dicts = []
892-
if which == 'major' or which == 'both':
892+
cbook._check_in_list(['major', 'minor', 'both'], which=which)
893+
if which in ['major', 'both']:
893894
dicts.append(self._major_tick_kw)
894-
if which == 'minor' or which == 'both':
895+
if which in ['minor', 'both']:
895896
dicts.append(self._minor_tick_kw)
896897
kwtrans = self._translate_tick_kw(kw)
897898

@@ -906,10 +907,10 @@ def set_tick_params(self, which='major', reset=False, **kw):
906907
self.reset_ticks()
907908
else:
908909
# apply the new kwargs to the existing ticks
909-
if which == 'major' or which == 'both':
910+
if which in ['major', 'both']:
910911
for tick in self.majorTicks:
911912
tick._apply_params(**kwtrans)
912-
if which == 'minor' or which == 'both':
913+
if which in ['minor', 'both']:
913914
for tick in self.minorTicks:
914915
tick._apply_params(**kwtrans)
915916
# special-case label color to also apply to the offset

0 commit comments

Comments
 (0)