@@ -2086,6 +2086,20 @@ def has_data(self):
2086
2086
mlines .Line2D , mpatches .Patch ))
2087
2087
for a in self ._children )
2088
2088
2089
+ def _deprecate_noninstance (self , _name , _types , ** kwargs ):
2090
+ """
2091
+ For each *key, value* pair in *kwargs*, check that *value* is an
2092
+ instance of one of *_types*; if not, raise an appropriate deprecation.
2093
+ """
2094
+ for key , value in kwargs .items ():
2095
+ if not isinstance (value , _types ):
2096
+ cbook .warn_deprecated (
2097
+ '3.4' , name = _name ,
2098
+ message = f'Passing argument *{ key } * of unexpected type '
2099
+ f'{ type (value ).__qualname__ } to %(name)s which only '
2100
+ f'accepts { _types } is deprecated since %(since)s and will '
2101
+ 'become an error %(removal)s.' )
2102
+
2089
2103
def add_artist (self , a ):
2090
2104
"""
2091
2105
Add an `~.Artist` to the Axes; return the artist.
@@ -2129,6 +2143,8 @@ def add_collection(self, collection, autolim=True):
2129
2143
"""
2130
2144
Add a `~.Collection` to the Axes; return the collection.
2131
2145
"""
2146
+ self ._deprecate_noninstance ('add_collection' , mcoll .Collection ,
2147
+ collection = collection )
2132
2148
label = collection .get_label ()
2133
2149
if not label :
2134
2150
collection .set_label (f'_child{ len (self ._children )} ' )
@@ -2152,6 +2168,7 @@ def add_image(self, image):
2152
2168
"""
2153
2169
Add an `~.AxesImage` to the Axes; return the image.
2154
2170
"""
2171
+ self ._deprecate_noninstance ('add_image' , mimage .AxesImage , image = image )
2155
2172
self ._set_artist_props (image )
2156
2173
if not image .get_label ():
2157
2174
image .set_label (f'_child{ len (self ._children )} ' )
@@ -2168,6 +2185,7 @@ def add_line(self, line):
2168
2185
"""
2169
2186
Add a `.Line2D` to the Axes; return the line.
2170
2187
"""
2188
+ self ._deprecate_noninstance ('add_line' , mlines .Line2D , line = line )
2171
2189
self ._set_artist_props (line )
2172
2190
if line .get_clip_path () is None :
2173
2191
line .set_clip_path (self .patch )
@@ -2184,6 +2202,7 @@ def _add_text(self, txt):
2184
2202
"""
2185
2203
Add a `~.Text` to the Axes; return the text.
2186
2204
"""
2205
+ self ._deprecate_noninstance ('_add_text' , mtext .Text , txt = txt )
2187
2206
self ._set_artist_props (txt )
2188
2207
self ._children .append (txt )
2189
2208
txt ._remove_method = self ._children .remove
@@ -2238,6 +2257,7 @@ def add_patch(self, p):
2238
2257
"""
2239
2258
Add a `~.Patch` to the Axes; return the patch.
2240
2259
"""
2260
+ self ._deprecate_noninstance ('add_patch' , mpatches .Patch , p = p )
2241
2261
self ._set_artist_props (p )
2242
2262
if p .get_clip_path () is None :
2243
2263
p .set_clip_path (self .patch )
@@ -2276,6 +2296,7 @@ def add_table(self, tab):
2276
2296
"""
2277
2297
Add a `~.Table` to the Axes; return the table.
2278
2298
"""
2299
+ self ._deprecate_noninstance ('add_table' , mtable .Table , tab = tab )
2279
2300
self ._set_artist_props (tab )
2280
2301
self ._children .append (tab )
2281
2302
tab .set_clip_path (self .patch )
0 commit comments