@@ -2150,6 +2150,20 @@ def has_data(self):
2150
2150
mlines .Line2D , mpatches .Patch ))
2151
2151
for a in self ._children )
2152
2152
2153
+ def _deprecate_noninstance (self , _name , _types , ** kwargs ):
2154
+ """
2155
+ For each *key, value* pair in *kwargs*, check that *value* is an
2156
+ instance of one of *_types*; if not, raise an appropriate deprecation.
2157
+ """
2158
+ for key , value in kwargs .items ():
2159
+ if not isinstance (value , _types ):
2160
+ _api .warn_deprecated (
2161
+ '3.5' , name = _name ,
2162
+ message = f'Passing argument *{ key } * of unexpected type '
2163
+ f'{ type (value ).__qualname__ } to %(name)s which only '
2164
+ f'accepts { _types } is deprecated since %(since)s and will '
2165
+ 'become an error %(removal)s.' )
2166
+
2153
2167
def add_artist (self , a ):
2154
2168
"""
2155
2169
Add an `~.Artist` to the Axes; return the artist.
@@ -2193,6 +2207,8 @@ def add_collection(self, collection, autolim=True):
2193
2207
"""
2194
2208
Add a `~.Collection` to the Axes; return the collection.
2195
2209
"""
2210
+ self ._deprecate_noninstance ('add_collection' , mcoll .Collection ,
2211
+ collection = collection )
2196
2212
label = collection .get_label ()
2197
2213
if not label :
2198
2214
collection .set_label (f'_child{ len (self ._children )} ' )
@@ -2225,6 +2241,7 @@ def add_image(self, image):
2225
2241
"""
2226
2242
Add an `~.AxesImage` to the Axes; return the image.
2227
2243
"""
2244
+ self ._deprecate_noninstance ('add_image' , mimage .AxesImage , image = image )
2228
2245
self ._set_artist_props (image )
2229
2246
if not image .get_label ():
2230
2247
image .set_label (f'_child{ len (self ._children )} ' )
@@ -2241,6 +2258,7 @@ def add_line(self, line):
2241
2258
"""
2242
2259
Add a `.Line2D` to the Axes; return the line.
2243
2260
"""
2261
+ self ._deprecate_noninstance ('add_line' , mlines .Line2D , line = line )
2244
2262
self ._set_artist_props (line )
2245
2263
if line .get_clip_path () is None :
2246
2264
line .set_clip_path (self .patch )
@@ -2257,6 +2275,7 @@ def _add_text(self, txt):
2257
2275
"""
2258
2276
Add a `~.Text` to the Axes; return the text.
2259
2277
"""
2278
+ self ._deprecate_noninstance ('_add_text' , mtext .Text , txt = txt )
2260
2279
self ._set_artist_props (txt )
2261
2280
self ._children .append (txt )
2262
2281
txt ._remove_method = self ._children .remove
@@ -2311,6 +2330,7 @@ def add_patch(self, p):
2311
2330
"""
2312
2331
Add a `~.Patch` to the Axes; return the patch.
2313
2332
"""
2333
+ self ._deprecate_noninstance ('add_patch' , mpatches .Patch , p = p )
2314
2334
self ._set_artist_props (p )
2315
2335
if p .get_clip_path () is None :
2316
2336
p .set_clip_path (self .patch )
@@ -2351,6 +2371,7 @@ def add_table(self, tab):
2351
2371
"""
2352
2372
Add a `~.Table` to the Axes; return the table.
2353
2373
"""
2374
+ self ._deprecate_noninstance ('add_table' , mtable .Table , tab = tab )
2354
2375
self ._set_artist_props (tab )
2355
2376
self ._children .append (tab )
2356
2377
tab .set_clip_path (self .patch )
0 commit comments