Skip to content

BUG: Prevent Tick params calls from overwriting visibility without being told to #12839

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 6 commits into from
Feb 25, 2019
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 @@ -832,6 +832,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 @@ -840,14 +843,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 @@ -4871,6 +4871,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test could be easily done without an image comparison by just checking the visibility of the ticks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tricky bit is that one of the common ways in tests of checking wheter the ticks are visible was lying to you prior to this PR, (though if you went to the individual ticks, it would be correct) As such, I was looking to make sure it translated to the image generated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can instead save to svg and use some long-ish strings as labels, and check that the labels don't appear as substrings in the svg file.



def test_tick_label_update():
# test issue 9397

Expand Down