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

Skip to content

Commit eb92f62

Browse files
authored
Merge pull request #12839 from ksunden/tick_params
BUG: Prevent Tick params calls from overwriting visibility without being told to
2 parents 65e4893 + d501de7 commit eb92f62

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ def set_tick_params(self, which='major', reset=False, **kw):
859859
if which == 'minor' or which == 'both':
860860
dicts.append(self._minor_tick_kw)
861861
kwtrans = self._translate_tick_kw(kw)
862+
863+
# this stashes the parameter changes so any new ticks will
864+
# automatically get them
862865
for d in dicts:
863866
if reset:
864867
d.clear()
@@ -867,14 +870,18 @@ def set_tick_params(self, which='major', reset=False, **kw):
867870
if reset:
868871
self.reset_ticks()
869872
else:
873+
# apply the new kwargs to the existing ticks
870874
if which == 'major' or which == 'both':
871875
for tick in self.majorTicks:
872-
tick._apply_params(**self._major_tick_kw)
876+
tick._apply_params(**kwtrans)
873877
if which == 'minor' or which == 'both':
874878
for tick in self.minorTicks:
875-
tick._apply_params(**self._minor_tick_kw)
879+
tick._apply_params(**kwtrans)
880+
# special-case label color to also apply to the offset
881+
# text
876882
if 'labelcolor' in kwtrans:
877883
self.offsetText.set_color(kwtrans['labelcolor'])
884+
878885
self.stale = True
879886

880887
@staticmethod

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,6 +4922,17 @@ def test_set_get_ticklabels():
49224922
ax[1].set_yticklabels(ax[0].get_yticklabels())
49234923

49244924

4925+
@image_comparison(
4926+
baseline_images=['retain_tick_visibility'],
4927+
extensions=['png'],
4928+
)
4929+
def test_retain_tick_visibility():
4930+
fig, ax = plt.subplots()
4931+
plt.plot([0, 1, 2], [0, -1, 4])
4932+
plt.setp(ax.get_yticklabels(), visible=False)
4933+
ax.tick_params(axis="y", which="both", length=0)
4934+
4935+
49254936
def test_tick_label_update():
49264937
# test issue 9397
49274938

0 commit comments

Comments
 (0)