@@ -2311,6 +2311,70 @@ def get_instancemethod(self):
2311
2311
return getattr (self .parent_obj , self .instancemethod_name )
2312
2312
2313
2313
2314
+ _art_list_msg = ("The use of Axes.lines, Axes.patches, Axes.texts "
2315
+ "Axes.tables, Axes.artists, Axes.collections, "
2316
+ "Axes.containers, "
2317
+ "and Axes.images have been "
2318
+ "deprecated. All artists are now stored is a single "
2319
+ "tree accessible via the Axes.artist_tree property. "
2320
+ "Please use the ``remove`` method on the artists to remove"
2321
+ "them from an Axes. \n \n "
2322
+ "These lists will be removed in 1.7 or 2.0." )
2323
+
2324
+
2325
+ class MPLRemoverList (list ):
2326
+ """
2327
+
2328
+ This is a sub-class of list which implements the logic to manage the
2329
+ backwards compatibility during deprecation of the lines, patches,
2330
+ texts, tables, artists, images, collections, and containers
2331
+ attributes from the Axes class. This will allow users to continue
2332
+ to use `ax.lines.pop()` to remove lines from an axes, even though
2333
+ the draw method no longer looks at those lists at render time.
2334
+
2335
+ This class will be removed when the list are.
2336
+
2337
+ """
2338
+ def __delslice__ (self , a , b ):
2339
+ # warn
2340
+ warnings .warn (_art_list_msg , mplDeprecation , stacklevel = 1 )
2341
+ # grab what we will be removing
2342
+ res = self [a :b ]
2343
+ # remove it from this list
2344
+ super (MPLRemoverList , self ).__delslice__ (self , a , b )
2345
+ # see if we need to call the real remove
2346
+ # Artist.remove sets _axes = None so if this is called
2347
+ # remove it won't be called again, but if a user removes
2348
+ # an artist from these lists directly, remove will correctly
2349
+ # be called.
2350
+ for a in res :
2351
+ # this works because of details of how Artist.remove works
2352
+ if a .axes :
2353
+ a .remove ()
2354
+
2355
+ def __delitem__ (self , y ):
2356
+ # see __delslice__ for explanation of logic
2357
+ warnings .warn (_art_list_msg , mplDeprecation , stacklevel = 1 )
2358
+ res = self [y ]
2359
+ super (MPLRemoverList , self ).__delitem__ (self , y )
2360
+ if res .axes :
2361
+ res .remove ()
2362
+
2363
+ def pop (self , i ):
2364
+ # see __delslice__ for explanation of logic
2365
+ warnings .warn (_art_list_msg , mplDeprecation , stacklevel = 1 )
2366
+ res = super (MPLRemoverList , self ).pop (self , i )
2367
+ if res .axes :
2368
+ res .remove ()
2369
+
2370
+ def remove (self , item ):
2371
+ # see __delslice__ for explanation of logic
2372
+ warnings .warn (_art_list_msg , mplDeprecation , stacklevel = 1 )
2373
+ res = super (MPLRemoverList , self ).remove (self , item )
2374
+ if item .axes :
2375
+ res .remove ()
2376
+
2377
+
2314
2378
# Numpy > 1.6.x deprecates putmask in favor of the new copyto.
2315
2379
# So long as we support versions 1.6.x and less, we need the
2316
2380
# following local version of putmask. We choose to make a
0 commit comments