8000 Merge pull request #9670 from jklymak/fixtickleft · matplotlib/matplotlib@c508c35 · GitHub
[go: up one dir, main page]

Skip to content

Commit c508c35

Browse files
authored
Merge pull request #9670 from jklymak/fixtickleft
FIX: Make tick_left/right keep labels off if they are already off
2 parents 1df45a4 + 17a615e commit c508c35

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

lib/matplotlib/axis.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,12 +1938,30 @@ def set_ticks_position(self, position):
19381938
self 8000 .stale = True
19391939

19401940
def tick_top(self):
1941-
'use ticks only on top'
1941+
"""
1942+
Move ticks and ticklabels (if present) to the top of the axes.
1943+
"""
1944+
label = True
1945+
if 'label1On' in self._major_tick_kw:
1946+
label = (self._major_tick_kw['label1On']
1947+
or self._major_tick_kw['label2On'])
19421948
self.set_ticks_position('top')
1949+
# if labels were turned off before this was called
1950+
# leave them off
1951+
self.set_tick_params(which='both', labeltop=label)
19431952

19441953
def tick_bottom(self):
1945-
'use ticks only on bottom'
1954+
"""
1955+
Move ticks and ticklabels (if present) to the bottom of the axes.
1956+
"""
1957+
label = True
1958+
if 'label1On' in self._major_tick_kw:
1959+
label = (self._major_tick_kw['label1On']
1960+
or self._major_tick_kw['label2On'])
19461961
self.set_ticks_position('bottom')
1962+
# if labels were turned off before this was called
1963+
# leave them off
1964+
self.set_tick_params(which='both', labelbottom=label)
19471965

19481966
def get_ticks_position(self):
19491967
"""
@@ -2277,12 +2295,30 @@ def set_ticks_position(self, position):
22772295
self.stale = True
22782296

22792297
def tick_right(self):
2280-
'use ticks only on right'
2298+
"""
2299+
Move ticks and ticklabels (if present) to the right of the axes.
2300+
"""
2301+
label = True
2302+
if 'label1On' in self._major_tick_kw:
2303+
label = (self._major_tick_kw['label1On']
2304+
or self._major_tick_kw['label2On'])
22812305
self.set_ticks_position('right')
2306+
# if labels were turned off before this was called
2307+
# leave them off
2308+
self.set_tick_params(which='both', labelright=label)
22822309

22832310
def tick_left(self):
2284-
'use ticks only on left'
2311+
"""
2312+
Move ticks and ticklabels (if present) to the left of the axes.
2313+
"""
2314+
label = True
2315+
if 'label1On' in 8000 self._major_tick_kw:
2316+
label = (self._major_tick_kw['label1On']
2317+
or self._major_tick_kw['label2On'])
22852318
self.set_ticks_position('left')
2319+
# if labels were turned off before this was called
2320+
# leave them off
2321+
self.set_tick_params(which='both', labelleft=label)
22862322

22872323
def get_ticks_position(self):
22882324
"""

lib/matplotlib/tests/test_subplots.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def test_shared():
101101
check_visible(axs, [False, False, True, True], [True, False, True, False])
102102

103103

104+
def test_shared_and_moved():
105+
# test if sharey is on, but then tick_left is called that labels don't
106+
# re-appear. Seaborn does this just to be sure yaxis is on left...
107+
f, (a1, a2) = plt.subplots(1, 2, sharey=True)
108+
check_visible([a2], [True], [False])
109+
a2.yaxis.tick_left()
110+
check_visible([a2], [True], [False])
111+
112+
f, (a1, a2) = plt.subplots(2, 1, sharex=True)
113+
check_visible([a1], [False], [True])
114+
a2.xaxis.tick_bottom()
115+
check_visible([a1], [False], [True])
116+
117+
104118
def test_exceptions():
105119
# TODO should this test more options?
106120
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)
0