8000 Make relim() take images into account too. · matplotlib/matplotlib@06f896a · GitHub
[go: up one dir, main page]

Skip to content

Commit 06f896a

Browse files
committed
Make relim() take images into account too.
1 parent 3441571 commit 06f896a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,10 @@ def add_image(self, image):
18601860
self.stale = True
18611861
return image
18621862

1863+
def _update_image_limits(self, image):
1864+
xmin, xmax, ymin, ymax = image.get_extent()
1865+
self.axes.update_datalim(((xmin, ymin), (xmax, ymax)))
1866+
18631867
def add_line(self, line):
18641868
"""
18651869
Add a :class:`~matplotlib.lines.Line2D` to the list of plot
@@ -2036,6 +2040,10 @@ def relim(self, visible_only=False):
20362040
if not visible_only or p.get_visible():
20372041
self._update_patch_limits(p)
20382042

2043+
for image in self.images:
2044+
if not visible_only or image.get_visible():
2045+
self._update_image_limits(image)
2046+
20392047
def update_datalim(self, xys, updatex=True, updatey=True):
20402048
"""
20412049
Update the data lim bbox with seq of xy tups or equiv. 2-D array

lib/matplotlib/tests/test_image.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,11 @@ def test_composite(fmt, counted, composite_image, count):
868868
buf = io.BytesIO()
869869
fig.savefig(buf, format=fmt)
870870
assert buf.getvalue().count(counted) == count
871+
872+
873+
def test_relim():
874+
fig, ax = plt.subplots()
875+
ax.imshow([[0]], extent=(0, 1, 0, 1))
876+
ax.relim()
877+
ax.autoscale()
878+
assert ax.get_xlim() == ax.get_ylim() == (0, 1)

0 commit comments

Comments
 (0)
0