@@ -24,7 +24,8 @@ def check_shared(axs, x_shared, y_shared):
24
24
i1 , i2 , "not " if shared [i1 , i2 ] else "" , name )
25
25
26
26
27
- def check_visible (axs , x_visible , y_visible ):
27
+ def check_ticklabel_visible (axs , x_visible , y_visible ):
28
+ """Check that the x and y ticklabel visibility is as specified."""
28
29
for i , (ax , vx , vy ) in enumerate (zip (axs , x_visible , y_visible )):
29
30
for l in ax .get_xticklabels () + [ax .xaxis .offsetText ]:
30
31
assert l .get_visible () == vx , \
@@ -40,6 +41,20 @@ def check_visible(axs, x_visible, y_visible):
40
41
assert ax .get_ylabel () == ""
41
42
42
43
44
+ def check_tick1_visible (axs, x_visible , y_visible ):
45
+ """
46
+ Check that the x and y tick visibility is as specified.
47
+
48
+ Note: This only checks the tick1line, i.e. bottom / left ticks.
49
+ """
50
+ for ax , visible , in zip (axs , x_visible ):
51
+ for tick in ax .xaxis .get_major_ticks ():
52
+ assert tick .tick1line .get_visible () == visible
53
+ for ax , y_visible , in zip (axs , y_visible ):
54
+ for tick in ax .yaxis .get_major_ticks ():
55
+ assert tick .tick1line .get_visible () == visible
56
+
57
+
43
58
def test_shared ():
44
59
rdim = (4 , 4 , 2 )
45
60
share = {
@@ -90,16 +105,24 @@ def test_shared():
90
105
f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = xo , sharey = yo )
91
106
axs = [a1 , a2 , a3 , a4 ]
92
107
check_shared (axs , share [xo ], share [yo ])
93
- check_visible (axs , visible ['x' ][xo ], visible ['y' ][yo ])
108
+ check_ticklabel_visible (axs , visible ['x' ][xo ], visible ['y' ][yo ])
94
109
plt .close (f )
95
110
96
- # test label_outer
97
- f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = True , sharey = True )
98
- axs = [a1 , a2 , a3 , a4 ]
99
- for ax in axs :
111
+
112
+ @pytest .mark .parametrize ('remove_ticks' , [True , False ])
113
+ def test_label_outer (remove_ticks ):
114
+ f , axs = plt .subplots (2 , 2 , sharex = True , sharey = True )
115
+ for ax in axs .flat :
100
116
ax .set (xlabel = "foo" , ylabel = "bar" )
101
- ax .label_outer ()
102
- check_visible (axs , [False , False , True , True ], [True , False , True , False ])
117
+ ax .label_outer (remove_inner_ticks = remove_ticks )
118
+ check_ticklabel_visible (
119
+ axs .flat , [False , False , True , True ], [True , False , True , False ])
120
+ if remove_ticks :
121
+ check_tick1_visible (
122
+ axs .flat , [False , False , True , True ], [True , False , True , False ])
123
+ else :
124
+ check_tick1_visible (
125
+ axs .flat , [True , True , True , True ], [True , True , True , True ])
103
126
104
127
105
128
def test_label_outer_span ():
@@ -118,28 +141,28 @@ def test_label_outer_span():
118
141
a4 = fig .add_subplot (gs [2 , 1 ])
119
142
for ax in fig .axes :
120
143
ax .label_outer ()
121
- check_visible (
144
+ check_ticklabel_visible (
122
145
fig .axes , [False , True , False , True ], [True , True , False , False ])
123
146
124
147
125
148
def test_label_outer_non_gridspec ():
126
149
ax = plt .axes ([0 , 0 , 1 , 1 ])
127
150
ax .label_outer () # Does nothing.
128
- check_visible ([ax ], [True ], [True ])
151
+ check_ticklabel_visible ([ax ], [True ], [True ])
129
152
130
153
131
154
def test_shared_and_moved ():
132
155
# test if sharey is on, but then tick_left is called that labels don't
133
156
# re-appear. Seaborn does this just to be sure yaxis is on left...
134
157
f , (a1 , a2 ) = plt .subplots (1 , 2 , sharey = True )
135
- check_visible ([a2 ], [True ], [False ])
158
+ check_ticklabel_visible ([a2 ], [True ], [False ])
136
159
a2 .yaxis .tick_left ()
137
- check_visible ([a2 ], [True ], [False ])
160
+ check_ticklabel_visible ([a2 ], [True ], [False ])
138
161
139
162
f , (a1 , a2 ) = plt .subplots (2 , 1 , sharex = True )
140
- check_visible ([a1 ], [False ], [True ])
163
+ check_ticklabel_visible ([a1 ], [False ], [True ])
141
164
a2 .xaxis .tick_bottom ()
142
- check_visible ([a1 ], [False ], [True ])
165
+ check_ticklabel_visible ([a1 ], [False ], [True ])
143
166
144
167
145
168
def test_exceptions ():
0 commit comments