FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make tick_left/right keep labels off if they are already off by jklymak · Pull Request #9670 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
44 changes: 40 additions & 4 deletions lib/matplotlib/axis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1938,12 +1938,30 @@ 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']
or self._major_tick_kw['label2On'])
self.set_ticks_position('top')
# if labels were turned off before this was called
# leave them off
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']
or self._major_tick_kw['label2On'])
self.set_ticks_position('bottom')
# if labels were turned off before this was called
# leave them off
self.set_tick_params(which='both', labelbottom=label)

def get_ticks_position(self):
"""
Expand Down Expand Up @@ -2274,12 +2292,30 @@ 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']
or self._major_tick_kw['label2On'])
self.set_ticks_position('right')
# if labels were turned off before this was called
# leave them off
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']
or self._major_tick_kw['label2On'])
self.set_ticks_position('left')
# if labels were turned off before this was called
# leave them off
self.set_tick_params(which='both', labelleft=label)

def get_ticks_position(self):
"""
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_subplots.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL