12
12
from nose .tools import assert_raises
13
13
14
14
15
- def check_shared (results , f , axs ):
15
+ def check_shared (axs , x_shared , y_shared ):
16
16
"""
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.
20
19
"""
21
- shared_str = ['x' , 'y' ]
22
20
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 ):
38
33
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 ):
40
35
for l in ax .get_xticklabels () + [ax .get_xaxis ().offsetText ]:
41
36
assert l .get_visible () == vx , \
42
37
"X axis was incorrectly %s" % (tostr (vx ))
@@ -45,6 +40,7 @@ def check_visible(result, f, axs):
45
40
"Y axis was incorrectly %s" % (tostr (vy ))
46
41
47
42
43
+ @cleanup
48
44
def test_shared ():
49
45
rdim = (4 , 4 , 2 )
50
46
share = {
@@ -85,8 +81,7 @@ def test_shared():
85
81
# test default
86
82
f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 )
87
83
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' ])
90
85
plt .close (f )
91
86
92
87
# test all option combinations
@@ -95,19 +90,16 @@ def test_shared():
95
90
for yo in ops :
96
91
f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = xo , sharey = yo )
97
92
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 ])
102
95
plt .close (f )
103
96
104
97
# test label_outer
105
98
f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = True , sharey = True )
106
99
axs = [a1 , a2 , a3 , a4 ]
107
100
for ax in axs :
108
101
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 ])
111
103
112
104
113
105
0 commit comments