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