Skip to content

Backport PR #12839 on branch v3.1.x (BUG: Prevent Tick params calls from overwriting visibility without being told to) #13518

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
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
11 changes: 9 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ def set_tick_params(self, which='major', reset=False, **kw):
if which == 'minor' or which == 'both':
dicts.append(self._minor_tick_kw)
kwtrans = self._translate_tick_kw(kw)

# this stashes the parameter changes so any new ticks will
# automatically get them
for d in dicts:
if reset:
d.clear()
Expand All @@ -867,14 +870,18 @@ def set_tick_params(self, which='major', reset=False, **kw):
if reset:
self.reset_ticks()
else:
# apply the new kwargs to the existing ticks
if which == 'major' or which == 'both':
for tick in self.majorTicks:
tick._apply_params(**self._major_tick_kw)
tick._apply_params(**kwtrans)
if which == 'minor' or which == 'both':
for tick in self.minorTicks:
tick._apply_params(**self._minor_tick_kw)
tick._apply_params(**kwtrans)
# special-case label color to also apply to the offset
# text
if 'labelcolor' in kwtrans:
self.offsetText.set_color(kwtrans['labelcolor'])

self.stale = True

@staticmethod
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4922,6 +4922,17 @@ def test_set_get_ticklabels():
ax[1].set_yticklabels(ax[0].get_yticklabels())


@image_comparison(
baseline_images=['retain_tick_visibility'],
extensions=['png'],
)
def test_retain_tick_visibility():
fig, ax = plt.subplots()
plt.plot([0, 1, 2], [0, -1, 4])
plt.setp(ax.get_yticklabels(), visible=False)
ax.tick_params(axis="y", which="both", length=0)


def test_tick_label_update():
# test issue 9397

Expand Down