@@ -206,8 +206,8 @@ def test_subplot_replace_projection():
206206 ax = plt .subplot (1 , 2 , 1 )
207207 ax1 = plt .subplot (1 , 2 , 1 )
208208 ax2 = plt .subplot (1 , 2 , 2 )
209- # This will delete ax / ax1 as they fully overlap
210- ax3 = plt .subplot (1 , 2 , 1 , projection = 'polar' )
209+ with pytest . warns ( MatplotlibDeprecationWarning ):
210+ ax3 = plt .subplot (1 , 2 , 1 , projection = 'polar' )
211211 ax4 = plt .subplot (1 , 2 , 1 , projection = 'polar' )
212212 assert ax is not None
213213 assert ax1 is ax
@@ -228,6 +228,7 @@ def test_subplot_kwarg_collision():
228228 ax1 = plt .subplot (projection = 'polar' , theta_offset = 0 )
229229 ax2 = plt .subplot (projection = 'polar' , theta_offset = 0 )
230230 assert ax1 is ax2
231+ ax1 .remove ()
231232 ax3 = plt .subplot (projection = 'polar' , theta_offset = 1 )
232233 assert ax1 is not ax3
233234 assert ax1 not in plt .gcf ().axes
@@ -274,13 +275,16 @@ def test_subplot_projection_reuse():
274275 assert ax1 is plt .gca ()
275276 # make sure we get it back if we ask again
276277 assert ax1 is plt .subplot (111 )
278+ # remove it
279+ ax1 .remove ()
277280 # create a polar plot
278281 ax2 = plt .subplot (111 , projection = 'polar' )
279282 assert ax2 is plt .gca ()
280283 # this should have deleted the first axes
281284 assert ax1 not in plt .gcf ().axes
282285 # assert we get it back if no extra parameters passed
283286 assert ax2 is plt .subplot (111 )
287+ ax2 .remove ()
284288 # now check explicitly setting the projection to rectilinear
285289 # makes a new axes
286290 ax3 = plt .subplot (111 , projection = 'rectilinear' )
@@ -302,15 +306,19 @@ def test_subplot_polar_normalization():
302306
303307
304308def test_subplot_change_projection ():
309+ created_axes = set ()
305310 ax = plt .subplot ()
311+ created_axes .add (ax )
306312 projections = ('aitoff' , 'hammer' , 'lambert' , 'mollweide' ,
307313 'polar' , 'rectilinear' , '3d' )
308314 for proj in projections :
309- ax_next = plt .subplot (projection = proj )
310- assert ax_next is plt .subplot ()
311- assert ax_next .name == proj
312- assert ax is not ax_next
313- ax = ax_next
315+ ax .remove ()
316+ ax = plt .subplot (projection = proj )
317+ assert ax is plt .subplot ()
318+ assert ax .name == proj
319+ created_axes .add (ax )
320+ # Check that each call created a new Axes.
321+ assert len (created_axes ) == 1 + len (projections )
314322
315323
316324def test_polar_second_call ():
0 commit comments