@@ -2064,6 +2064,20 @@ def has_data(self):
2064
2064
mlines .Line2D , mpatches .Patch ))
2065
2065
for a in self ._children )
2066
2066
2067
+ def _deprecate_noninstance (self , _name , _types , ** kwargs ):
2068
+ """
2069
+ For each *key, value* pair in *kwargs*, check that *value* is an
2070
+ instance of one of *_types*; if not, raise an appropriate deprecation.
2071
+ """
2072
+ for key , value in kwargs .items ():
2073
+ if not isinstance (value , _types ):
2074
+ cbook .warn_deprecated (
2075
+ '3.4' , name = _name ,
2076
+ message = f'Passing argument *{ key } * of unexpected type '
2077
+ f'{ type (value ).__qualname__ } to %(name)s which only '
2078
+ f'accepts { _types } is deprecated since %(since)s and will '
2079
+ 'become an error %(removal)s.' )
2080
+
2067
2081
def add_artist (self , a ):
2068
2082
"""
2069
2083
Add an `~.Artist` to the Axes; return the artist.
@@ -2107,6 +2121,8 @@ def add_collection(self, collection, autolim=True):
2107
2121
"""
2108
2122
Add a `~.Collection` to the Axes; return the collection.
2109
2123
"""
2124
+ self ._deprecate_noninstance ('add_collection' , mcoll .Collection ,
2125
+ collection = collection )
2110
2126
label = collection .get_label ()
2111
2127
if not label :
2112
2128
collection .set_label (f'_child{ len (self ._children )} ' )
@@ -2130,6 +2146,7 @@ def add_image(self, image):
2130
2146
"""
2131
2147
Add an `~.AxesImage` to the Axes; return the image.
2132
2148
"""
2149
+ self ._deprecate_noninstance ('add_image' , mimage .AxesImage , image = image )
2133
2150
self ._set_artist_props (image )
2134
2151
if not image .get_label ():
2135
2152
image .set_label (f'_child{ len (self ._children )} ' )
@@ -2146,6 +2163,7 @@ def add_line(self, line):
2146
2163
"""
2147
2164
Add a `.Line2D` to the Axes; return the line.
2148
2165
"""
2166
+ self ._deprecate_noninstance ('add_line' , mlines .Line2D , line = line )
2149
2167
self ._set_artist_props (line )
2150
2168
if line .get_clip_path () is None :
2151
2169
line .set_clip_path (self .patch )
@@ -2162,6 +2180,7 @@ def _add_text(self, txt):
2162
2180
"""
2163
2181
Add a `~.Text` to the Axes; return the text.
2164
2182
"""
2183
+ self ._deprecate_noninstance ('_add_text' , mtext .Text , txt = txt )
2165
2184
self ._set_artist_props (txt )
2166
2185
self ._children .append (txt )
2167
2186
txt ._remove_method = self ._children .remove
@@ -2216,6 +2235,7 @@ def add_patch(self, p):
2216
2235
"""
2217
2236
Add a `~.Patch` to the Axes; return the patch.
2218
2237
"""
2238
+ self ._deprecate_noninstance ('add_patch' , mpatches .Patch , p = p )
2219
2239
self ._set_artist_props (p )
2220
2240
if p .get_clip_path () is None :
2221
2241
p .set_clip_path (self .patch )
@@ -2254,6 +2274,7 @@ def add_table(self, tab):
2254
2274
"""
2255
2275
Add a `~.Table` to the Axes; return the table.
2256
2276
"""
2277
+ self ._deprecate_noninstance ('add_table' , mtable .Table , tab = tab )
2257
2278
self ._set_artist_props (tab )
2258
2279
self ._children .append (tab )
2259
2280
tab .set_clip_path (self .patch )
0 commit comments