@@ -33,6 +33,12 @@ def check_visible(axs, x_visible, y_visible):
3333 for l in ax .get_yticklabels () + [ax .yaxis .offsetText ]:
3434 assert l .get_visible () == vy , \
3535 f"Visibility of y axis #{ i } is incorrectly { vy } "
36+ # axis label "visibility" is toggled by label_outer by resetting the
37+ # label to empty, but it can also be empty to start with.
38+ if not vx :
39+ assert ax .get_xlabel () == ""
40+ if not vy :
41+ assert ax .get_ylabel () == ""
3642
3743
3844def test_shared ():
@@ -92,6 +98,7 @@ def test_shared():
9298 f , ((a1 , a2 ), (a3 , a4 )) = plt .subplots (2 , 2 , sharex = True , sharey = True )
9399 axs = [a1 , a2 , a3 , a4 ]
94100 for ax in axs :
101+ ax .set (xlabel = "foo" , ylabel = "bar" )
95102 ax .label_outer ()
96103 check_visible (axs , [False , False , True , True ], [True , False , True , False ])
97104
@@ -164,7 +171,7 @@ def test_subplots_offsettext():
164171@pytest .mark .parametrize ("bottom" , [True , False ])
165172@pytest .mark .parametrize ("left" , [True , False ])
166173@pytest .mark .parametrize ("right" , [True , False ])
167- def test_subplots_hide_labels (top , bottom , left , right ):
174+ def test_subplots_hide_ticklabels (top , bottom , left , right ):
168175 # Ideally, we would also test offset-text visibility (and remove
169176 # test_subplots_offsettext), but currently, setting rcParams fails to move
170177 # the offset texts as well.
@@ -182,6 +189,23 @@ def test_subplots_hide_labels(top, bottom, left, right):
182189 assert yright == (right and j == 2 )
183190
184191
192+ @pytest .mark .parametrize ("xlabel_position" , ["bottom" , "top" ])
193+ @pytest .mark .parametrize ("ylabel_position" , ["left" , "right" ])
194+ def test_subplots_hide_axislabels (xlabel_position , ylabel_position ):
195+ axs = plt .figure ().subplots (3 , 3 , sharex = True , sharey = True )
196+ for (i , j ), ax in np .ndenumerate (axs ):
197+ ax .set (xlabel = "foo" , ylabel = "bar" )
198+ ax .xaxis .set_label_position (xlabel_position )
199+ ax .yaxis .set_label_position (ylabel_position )
200+ ax .label_outer ()
201+ assert bool (ax .get_xlabel ()) == (
202+ xlabel_position == "bottom" and i == 2
203+ or xlabel_position == "top" and i == 0 )
204+ assert bool (ax .get_ylabel ()) == (
205+ ylabel_position == "left" and j == 0
206+ or ylabel_position == "right" and j == 2 )
207+
208+
185209def test_get_gridspec ():
186210 # ahem, pretty trivial, but...
187211 fig , ax = plt .subplots ()
0 commit comments