@@ -2027,6 +2027,20 @@ def has_data(self):
2027
2027
mlines .Line2D , mpatches .Patch ))
2028
2028
for a in self ._children )
2029
2029
2030
+ def _deprecate_noninstance (self , _name , _types , ** kwargs ):
2031
+ """
2032
+ For each *key, value* pair in *kwargs*, check that *value* is an
2033
+ instance of one of *_types*; if not, raise an appropriate deprecation.
2034
+ """
2035
+ for key , value in kwargs .items ():
2036
+ if not isinstance (value , _types ):
2037
+ cbook .warn_deprecated (
2038
+ '3.4' , name = _name ,
2039
+ message = f'Passing argument *{ key } * of unexpected type '
2040
+ f'{ type (value ).__qualname__ } to %(name)s which only '
2041
+ f'accepts { _types } is deprecated since %(since)s and will '
2042
+ 'become an error %(removal)s.' )
2043
+
2030
2044
def add_artist (self , a ):
2031
2045
"""
2032
2046
Add an `~.Artist` to the Axes; return the artist.
@@ -2070,6 +2084,8 @@ def add_collection(self, collection, autolim=True):
2070
2084
"""
2071
2085
Add a `~.Collection` to the Axes; return the collection.
2072
2086
"""
2087
+ self ._deprecate_noninstance ('add_collection' , mcoll .Collection ,
2088
+ collection = collection )
2073
2089
label = collection .get_label ()
2074
2090
if not label :
2075
2091
collection .set_label (f'_collection{ len (self ._children )} ' )
@@ -2093,6 +2109,7 @@ def add_image(self, image):
2093
2109
"""
2094
2110
Add an `~.AxesImage` to the Axes; return the image.
2095
2111
"""
2112
+ self ._deprecate_noninstance ('add_image' , mimage .AxesImage , image = image )
2096
2113
self ._set_artist_props (image )
2097
2114
if not image .get_label ():
2098
2115
image .set_label (f'_image{ len (self ._children )} ' )
@@ -2109,6 +2126,7 @@ def add_line(self, line):
2109
2126
"""
2110
2127
Add a `.Line2D` to the Axes; return the line.
2111
2128
"""
2129
+ self ._deprecate_noninstance ('add_line' , mlines .Line2D , line = line )
2112
2130
self ._set_artist_props (line )
2113
2131
if line .get_clip_path () is None :
2114
2132
line .set_clip_path (self .patch )
@@ -2125,6 +2143,7 @@ def _add_text(self, txt):
2125
2143
"""
2126
2144
Add a `~.Text` to the Axes; return the text.
2127
2145
"""
2146
+ self ._deprecate_noninstance ('_add_text' , mtext .Text , txt = txt )
2128
2147
self ._set_artist_props (txt )
2129
2148
self ._children .append (txt )
2130
2149
txt ._remove_method = self ._children .remove
@@ -2179,6 +2198,7 @@ def add_patch(self, p):
2179
2198
"""
2180
2199
Add a `~.Patch` to the Axes; return the patch.
2181
2200
"""
2201
+ self ._deprecate_noninstance ('add_patch' , mpatches .Patch , p = p )
2182
2202
self ._set_artist_props (p )
2183
2203
if p .get_clip_path () is None :
2184
2204
p .set_clip_path (self .patch )
@@ -2217,6 +2237,7 @@ def add_table(self, tab):
2217
2237
"""
2218
2238
Add a `~.Table` to the Axes; return the table.
2219
2239
"""
2240
+ self ._deprecate_noninstance ('add_table' , mtable .Table , tab = tab )
2220
2241
self ._set_artist_props (tab )
2221
2242
self ._children .append (tab )
2222
2243
tab .set_clip_path (self .patch )
0 commit comments