8000 Saner(?) implementation of check_{shared,visible}. · matplotlib/matplotlib@a97cb54 · GitHub
[go: up one dir, main page]

Skip to content

Commit a97cb54

Browse files
committed
Saner(?) implementation of check_{shared,visible}.
Also cleanup after the tests.
1 parent 91b3019 commit a97cb54

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

lib/matplotlib/tests/test_subplots.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,26 @@
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']):
34+
for (ax, vx, vy) in zip(axs, x_visible, y_visible):
4035
for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]:
4136
assert l.get_visible() == vx, \
4237
"X axis was incorrectly %s" % (tostr(vx))
@@ -45,6 +40,7 @@ def check_visible(result, f, axs):
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,19 +90,16 @@ 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

10497
# test label_outer
10598
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=True, sharey=True)
10699
axs = [a1, a2, a3, a4]
107100
for ax in axs:
108101
ax.label_outer()
109-
check_visible(
110-
{'x': [False, False, True, True], 'y': [True, False, True, False]}, f, axs)
102+
check_visible(axs, [False, False, True, True], [True, False, True, False])
111103

112104

113105

0 commit comments

Comments
 (0)
0