8000 Merge pull request #15465 from timhoffm/validate-tick-params-which · matplotlib/matplotlib@09bcbdc · GitHub
[go: up one dir, main page]

Skip to content

Commit 09bcbdc

Browse files
authored
Merge pull request #15465 from timhoffm/validate-tick-params-which
Validate and simplify set_tick_params(which=...)
2 parents 5c8cd35 + 683d4c9 commit 09bcbdc

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
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: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -888,32 +888,29 @@ def set_tick_params(self, which='major', reset=False, **kw):
888888
For documentation of keyword arguments, see
889889
:meth:`matplotlib.axes.Axes.tick_params`.
890890
"""
891-
dicts = []
892-
if which == 'major' or which == 'both':
893-
dicts.append(self._major_tick_kw)
894-
if which == 'minor' or which == 'both':
895-
dicts.append(self._minor_tick_kw)
891+
cbook._check_in_list(['major', 'minor', 'both'], which=which)
896892
kwtrans = self._translate_tick_kw(kw)
897893

898-
# this stashes the parameter changes so any new ticks will
899-
# automatically get them
900-
for d in dicts:
901-
if reset:
902-
d.clear()
903-
d.update(kwtrans)
904-
894+
# the kwargs are stored in self._major/minor_tick_kw so that any
895+
# future new ticks will automatically get them
905896
if reset:
897+
if which in ['major', 'both']:
898+
self._major_tick_kw.clear()
899+
self._major_tick_kw.update(kwtrans)
900+
if which in ['minor', 'both']:
901+
self._minor_tick_kw.clear()
902+
self._minor_tick_kw.update(kwtrans)
906903
self.reset_ticks()
907904
else:
908-
# apply the new kwargs to the existing ticks
909-
if which == 'major' or which == 'both':
905+
if which in ['major', 'both']:
906+
self._major_tick_kw.update(kwtrans)
910907
for tick in self.majorTicks:
911908
tick._apply_params(**kwtrans)
912-
if which == 'minor' or which == 'both':
909+
if which in ['minor', 'both']:
910+
self._minor_tick_kw.update(kwtrans)
913911
for tick in self.minorTicks:
914912
tick._apply_params(**kwtrans)
915-
# special-case label color to also apply to the offset
916-
# text
913+
# special-case label color to also apply to the offset text
917914
if 'labelcolor' in kwtrans:
918915
self.offsetText.set_color(kwtrans['labelcolor'])
919916

0 commit comments

Comments
 (0)
0