Skip to content

Make tick_left/right keep labels off if they are already off #9670

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 5 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added test
  • Loading branch information
jklymak committed Nov 3, 2017
commit 17a615ec45ef44f68a11e5a32fbd57c0c9cc5ff4
16 changes: 12 additions & 4 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,9 @@ def set_ticks_position(self, position):
self.stale = True

def tick_top(self):
'use ticks only on top'
"""
Move ticks and ticklabels (if present) to the top of the axes.
"""
label = True
if 'label1On' in self._major_tick_kw:
label = (self._major_tick_kw['label1On']
Expand All @@ -1949,7 +1951,9 @@ def tick_top(self):
self.set_tick_params(which='both', labeltop=label)

def tick_bottom(self):
'use ticks only on bottom'
"""
Move ticks and ticklabels (if present) to the bottom of the axes.
"""
label = True
if 'label1On' in self._major_tick_kw:
label = (self._major_tick_kw['label1On']
Expand Down Expand Up @@ -2288,7 +2292,9 @@ def set_ticks_position(self, position):
self.stale = True

def tick_right(self):
'use ticks only on right'
"""
Move ticks and ticklabels (if present) to the right of the axes.
"""
label = True
if 'label1On' in self._major_tick_kw:
label = (self._major_tick_kw['label1On']
Expand All @@ -2299,7 +2305,9 @@ def tick_right(self):
self.set_tick_params(which='both', labelright=label)

def tick_left(self):
'use ticks only on left'
"""
Move ticks and ticklabels (if present) to the left of the axes.
"""
label = True
if 'label1On' in self._major_tick_kw:
label = (self._major_tick_kw['label1On']
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def test_shared():
check_visible(axs, [False, False, True, True], [True, False, True, False])


def test_shared_and_moved():
# test if sharey is on, but then tick_left is called that labels don't
# re-appear. Seaborn does this just to be sure yaxis is on left...
f, (a1, a2) = plt.subplots(1, 2, sharey=True)
check_visible([a2], [True], [False])
a2.yaxis.tick_left()
check_visible([a2], [True], [False])

f, (a1, a2) = plt.subplots(2, 1, sharex=True)
check_visible([a1], [False], [True])
a2.xaxis.tick_bottom()
check_visible([a1], [False], [True])


def test_exceptions():
# TODO should this test more options?
with pytest.raises(ValueError):
Expand Down