Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52a5906

Browse files
committed
Add Axes.add_image() for consistency.
1 parent 6ac203f commit 52a5906

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,7 +4537,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
45374537

45384538
im.set_data(X)
45394539
im.set_alpha(alpha)
4540-
self._set_artist_props(im)
45414540
if im.get_clip_path() is None:
45424541
# image does not already have clipping set, clip to axes patch
45434542
im.set_clip_path(self.patch)
@@ -4553,9 +4552,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
45534552
# to tightly fit the image, regardless of dataLim.
45544553
im.set_extent(im.get_extent())
45554554

4556-
self.images.append(im)
4557-
im._remove_method = lambda h: self.images.remove(h)
4558-
4555+
self.add_image(im)
45594556
return im
45604557

45614558
@staticmethod
@@ -5202,7 +5199,7 @@ def pcolorfast(self, *args, **kwargs):
52025199
**kwargs)
52035200
im.set_data(C)
52045201
im.set_alpha(alpha)
5205-
self.images.append(im)
5202+
self.add_image(im)
52065203
ret = im
52075204

52085205
if style == "pcolorimage":
@@ -5211,10 +5208,9 @@ def pcolorfast(self, *args, **kwargs):
52115208
norm=norm,
52125209
alpha=alpha,
52135210
**kwargs)
5214-
self.images.append(im)
5211+
self.add_image(im)
52155212
ret = im
52165213

5217-
self._set_artist_props(ret)
52185214
if vmin is not None or vmax is not None:
52195215
ret.set_clim(vmin, vmax)
52205216
else:

lib/matplotlib/axes/_base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,17 @@ def add_collection(self, collection, autolim=True):
14571457
collection._remove_method = lambda h: self.collections.remove(h)
14581458
return collection
14591459

1460+
def add_line(self, image):
1461+
"""
1462+
Add a :class:`~matplotlib.image.AxesImage` to the axes.
1463+
1464+
Returns the image.
1465+
"""
1466+
self._set_artist_props(image)
1467+
self.images.append(image)
1468+
im._remove_method = lambda h: self.images.remove(h)
1469+
return image
1470+
14601471
def add_line(self, line):
14611472
"""
14621473
Add a :class:`~matplotlib.lines.Line2D` to the list of plot

0 commit comments

Comments
 (0)