8000 Merge pull request #4446 from anntzer/label_outer-offsetText · matplotlib/matplotlib@448d9ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 448d9ed

Browse files
committed
Merge pull request #4446 from anntzer/label_outer-offsetText
Label outer offset text
2 parents 1111c1d + a97cb54 commit 448d9ed

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

lib/matplotlib/axes/_subplots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ def label_outer(self):
136136
firstcol = self.is_first_col()
137137
for label in self.get_xticklabels():
138138
label.set_visible(lastrow)
139-
139+
self.get_xaxis().get_offset_text().set_visible(lastrow)
140140
for label in self.get_yticklabels():
141141
label.set_visible(firstcol)
142+
self.get_yaxis().get_offset_text().set_visible(firstcol)
142143

143144
def _make_twin_axes(self, *kl, **kwargs):
144145
"""

lib/matplotlib/tests/test_subplots.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,35 @@
1212
from nose.tools import assert_raises
1313

1414

15-
def check_shared(results, f, axs):
15+
def check_shared(axs, x_shared, y_shared):
1616
"""
17-
results is a 4 x 4 x 2 matrix of boolean values where
18-
if [i, j, 0] == True, X axis for subplots i and j should be shared
19-
if [i, j, 1] == False, Y axis for subplots i and j should not be shared
17+
x_shared and y_shared are n x n boolean matrices; entry (i, j) indicates
18+
whether the x (or y) axes of subplots i and j should be shared.
2019
"""
21-
shared_str = ['x', 'y']
2220
shared = [axs[0]._shared_x_axes, axs[0]._shared_y_axes]
23-
#shared = {
24-
# 'x': a1._shared_x_axes,
25-
# 'y': a1._shared_y_axes,
26-
# }
27-
tostr = lambda r: "not " if r else ""
28-
for i1 in xrange(len(axs)):
29-
for i2 in xrange(i1 + 1, len(axs)):
30-
for i3 in xrange(len(shared)):
31-
assert shared[i3].joined(axs[i1], axs[i2]) == \
32-
results[i1, i2, i3], \
33-
"axes %i and %i incorrectly %ssharing %s axis" % \
34-
(i1, i2, tostr(results[i1, i2, i3]), shared_str[i3])
35-
36-
37-
def check_visible(result, f, axs):
21+
for (i1, ax1), (i2, ax2), (i3, (name, shared)) in zip(
22+
enumerate(axs),
23+
enumerate(axs),
24+
enumerate(zip("xy", [x_shared, y_shared]))):
25+
if i2 <= i1:
26+
continue
27+
assert shared[i3].joined(ax1, ax2) == shared[i1, i2], \
28+
"axes %i and %i incorrectly %ssharing %s axis" % (
29+
i1, i2, "not " if shared[i1, i2] else "", name)
30+
31+
32+
def check_visible(axs, x_visible, y_visible):
3833
tostr = lambda v: "invisible" if v else "visible"
39-
for (ax, vx, vy) in zip(axs, result['x'], result['y']):
40-
for l in ax.get_xticklabels():
34+
for (ax, vx, vy) in zip(axs, x_visible, y_visible):
35+
for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]:
4136
assert l.get_visible() == vx, \
4237
"X axis was incorrectly %s" % (tostr(vx))
43-
for l in ax.get_yticklabels():
38+
for l in ax.get_yticklabels() + [ax.get_yaxis().offsetText]:
4439
assert l.get_visible() == vy, \
4540
"Y axis was incorrectly %s" % (tostr(vy))
4641

4742

43+
@cleanup
4844
def test_shared():
4945
rdim = (4, 4, 2)
5046
share = {
@@ -85,8 +81,7 @@ def test_shared():
8581
# test default
8682
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2)
8783
axs = [a1, a2, a3, a4]
88-
check_shared(numpy.dstack((share['none'], share['none'])), \
89-
f, axs)
84+
check_shared(axs, share['none'], share['none'])
9085
plt.close(f)
9186

9287
# test all option combinations
@@ -95,12 +90,18 @@ def test_shared():
9590
for yo in ops:
9691
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=xo, sharey=yo)
9792
axs = [a1, a2, a3, a4]
98-
check_shared(numpy.dstack((share[xo], share[yo])), \
99-
f, axs)
100-
check_visible(dict(x=visible['x'][xo], y=visible['y'][yo]), \
101-
f, axs)
93+
check_shared(axs, share[xo], share[yo])
94+
check_visible(axs, visible['x'][xo], visible['y'][yo])
10295
plt.close(f)
10396

97+
# test label_outer
98+
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=True, sharey=True)
99+
axs = [a1, a2, a3, a4]
100+
for ax in axs:
101+
ax.label_outer()
102+
check_visible(axs, [False, False, True, True], [True, False, True, False])
103+
104+
104105

105106
def test_exceptions():
106107
# TODO should this test more options?

0 commit comments

Comments
 (0)
0