1- from collections .abc import Iterable , MutableSequence
1+ from collections .abc import Iterable , Sequence
22from contextlib import ExitStack
33import functools
44import inspect
@@ -1403,7 +1403,7 @@ def cla(self):
14031403 else :
14041404 self .clear ()
14051405
1406- class ArtistList (MutableSequence ):
1406+ class ArtistList (Sequence ):
14071407 """
14081408 A sublist of Axes children based on their type.
14091409
@@ -1414,7 +1414,7 @@ class ArtistList(MutableSequence):
14141414 This class exists only for the transition period to warn on the
14151415 deprecated modification of artist lists.
14161416 """
1417- def __init__ (self , axes , prop_name , add_name ,
1417+ def __init__ (self , axes , prop_name ,
14181418 valid_types = None , invalid_types = None ):
14191419 """
14201420 Parameters
@@ -1425,9 +1425,6 @@ def __init__(self, axes, prop_name, add_name,
14251425 prop_name : str
14261426 The property name used to access this sublist from the Axes;
14271427 used to generate deprecation warnings.
1428- add_name : str
1429- The method name used to add Artists of this sublist's type to
1430- the Axes; used to generate deprecation warnings.
14311428 valid_types : list of type, optional
14321429 A list of types that determine which children will be returned
14331430 by this sublist. If specified, then the Artists in the sublist
@@ -1442,7 +1439,6 @@ def __init__(self, axes, prop_name, add_name,
14421439 """
14431440 self ._axes = axes
14441441 self ._prop_name = prop_name
1445- self ._add_name = add_name
14461442 self ._type_check = lambda artist : (
14471443 (not valid_types or isinstance (artist , valid_types )) and
14481444 (not invalid_types or not isinstance (artist , invalid_types ))
@@ -1468,103 +1464,47 @@ def __getitem__(self, key):
14681464 def __add__ (self , other ):
14691465 if isinstance (other , (list , _AxesBase .ArtistList )):
14701466 return [* self , * other ]
1467+ if isinstance (other , (tuple , _AxesBase .ArtistList )):
1468+ return (* self , * other )
14711469 return NotImplemented
14721470
14731471 def __radd__ (self , other ):
14741472 if isinstance (other , list ):
14751473 return other + list (self )
1474+ if isinstance (other , tuple ):
1475+ return other + tuple (self )
14761476 return NotImplemented
14771477
1478- def insert (self , index , item ):
1479- _api .warn_deprecated (
1480- '3.5' ,
1481- name = f'modification of the Axes.{ self ._prop_name } ' ,
1482- obj_type = 'property' ,
1483- alternative = f'Axes.{ self ._add_name } ' )
1484- try :
1485- index = self ._axes ._children .index (self [index ])
1486- except IndexError :
1487- index = None
1488- getattr (self ._axes , self ._add_name )(item )
1489- if index is not None :
1490- # Move new item to the specified index, if there's something to
1491- # put it before.
1492- self ._axes ._children [index :index ] = self ._axes ._children [- 1 :]
1493- del self ._axes ._children [- 1 ]
1494-
1495- def __setitem__ (self , key , item ):
1496- _api .warn_deprecated (
1497- '3.5' ,
1498- name = f'modification of the Axes.{ self ._prop_name } ' ,
1499- obj_type = 'property' ,
1500- alternative = f'Artist.remove() and Axes.f{ self ._add_name } ' )
1501- del self [key ]
1502- if isinstance (key , slice ):
1503- key = key .start
1504- if not np .iterable (item ):
1505- self .insert (key , item )
1506- return
1507-
1508- try :
1509- index = self ._axes ._children .index (self [key ])
1510- except IndexError :
1511- index = None
1512- for i , artist in enumerate (item ):
1513- getattr (self ._axes , self ._add_name )(artist )
1514- if index is not None :
1515- # Move new items to the specified index, if there's something
1516- # to put it before.
1517- i = - (i + 1 )
1518- self ._axes ._children [index :index ] = self ._axes ._children [i :]
1519- del self ._axes ._children [i :]
1520-
1521- def __delitem__ (self , key ):
1522- _api .warn_deprecated (
1523- '3.5' ,
1524- name = f'modification of the Axes.{ self ._prop_name } ' ,
1525- obj_type = 'property' ,
1526- alternative = 'Artist.remove()' )
1527- if isinstance (key , slice ):
1528- for artist in self [key ]:
1529- artist .remove ()
1530- else :
1531- self [key ].remove ()
1532-
15331478 @property
15341479 def artists (self ):
1535- return self .ArtistList (self , 'artists' , 'add_artist' , invalid_types = (
1480+ return self .ArtistList (self , 'artists' , invalid_types = (
15361481 mcoll .Collection , mimage .AxesImage , mlines .Line2D , mpatches .Patch ,
15371482 mtable .Table , mtext .Text ))
15381483
15391484 @property
15401485 def collections (self ):
1541- return self .ArtistList (self , 'collections' , 'add_collection' ,
1486+ return self .ArtistList (self , 'collections' ,
15421487 valid_types = mcoll .Collection )
15431488
15441489 @property
15451490 def images (self ):
1546- return self .ArtistList (self , 'images' , 'add_image' ,
1547- valid_types = mimage .AxesImage )
1491+ return self .ArtistList (self , 'images' , valid_types = mimage .AxesImage )
15481492
15491493 @property
15501494 def lines (self ):
1551- return self .ArtistList (self , 'lines' , 'add_line' ,
1552- valid_types = mlines .Line2D )
1495+ return self .ArtistList (self , 'lines' , valid_types = mlines .Line2D )
15531496
15541497 @property
15551498 def patches (self ):
1556- return self .ArtistList (self , 'patches' , 'add_patch' ,
1557- valid_types = mpatches .Patch )
1499+ return self .ArtistList (self , 'patches' , valid_types = mpatches .Patch )
15581500
15591501 @property
15601502 def tables (self ):
1561- return self .ArtistList (self , 'tables' , 'add_table' ,
1562- valid_types = mtable .Table )
1503+ return self .ArtistList (self , 'tables' , valid_types = mtable .Table )
15631504
15641505 @property
15651506 def texts (self ):
1566- return self .ArtistList (self , 'texts' , 'add_artist' ,
1567- valid_types = mtext .Text )
1507+ return self .ArtistList (self , 'texts' , valid_types = mtext .Text )
15681508
15691509 def get_facecolor (self ):
15701510 """Get the facecolor of the Axes."""
0 commit comments