@@ -24,7 +24,8 @@ def check_shared(axs, x_shared, y_shared):
2424 i1 , i2 , "not " if shared [i1 , i2 ] else "" , name )
2525
2626
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."""
2829 for i , (ax , vx , vy ) in enumerate (zip (axs , x_visible , y_visible )):
2930 for l in ax .get_xticklabels () + [ax .xaxis .offsetText ]:
3031 assert l .get_visible () == vx , \
@@ -40,6 +41,20 @@ def check_visible(axs, x_visible, y_visible):
4041 assert ax .get_ylabel () == ""
4142
4243
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+
4358def test_shared ():
4459 rdim = (4 , 4 , 2 )
4560 share = {
@@ -90,16 +105,24 @@ def test_shared():
90105 f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = xo , sharey = yo )
91106 axs = [a1 , a2 , a3 , a4 ]
92107 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 ])
94109 plt .close (f )
95110
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 :
100116 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 ])
103126
104127
105128def test_label_outer_span ():
@@ -118,28 +141,28 @@ def test_label_outer_span():
118141 a4 = fig .add_subplot (gs [2 , 1 ])
119142 for ax in fig .axes :
120143 ax .label_outer ()
121- check_visible (
144+ check_ticklabel_visible (
122145 fig .axes , [False , True , False , True ], [True , True , False , False ])
123146
124147
125148def test_label_outer_non_gridspec ():
126149 ax = plt .axes ((0 , 0 , 1 , 1 ))
127150 ax .label_outer () # Does nothing.
128- check_visible ([ax ], [True ], [True ])
151+ check_ticklabel_visible ([ax ], [True ], [True ])
129152
130153
131154def test_shared_and_moved ():
132155 # test if sharey is on, but then tick_left is called that labels don't
133156 # re-appear. Seaborn does this just to be sure yaxis is on left...
134157 f , (a1 , a2 ) = plt .subplots (1 , 2 , sharey = True )
135- check_visible ([a2 ], [True ], [False ])
158+ check_ticklabel_visible ([a2 ], [True ], [False ])
136159 a2 .yaxis .tick_left ()
137- check_visible ([a2 ], [True ], [False ])
160+ check_ticklabel_visible ([a2 ], [True ], [False ])
138161
139162 f , (a1 , a2 ) = plt .subplots (2 , 1 , sharex = True )
140- check_visible ([a1 ], [False ], [True ])
163+ check_ticklabel_visible ([a1 ], [False ], [True ])
141164 a2 .xaxis .tick_bottom ()
142- check_visible ([a1 ], [False ], [True ])
165+ check_ticklabel_visible ([a1 ], [False ], [True ])
143166
144167
145168def test_exceptions ():
0 commit comments