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

Skip to content

Commit fd1ddaf

Browse files
committed
pyplot.gci: Look first in current axes, not most recently added axes.
This fixes a bug in which the behavior of gci did not match its docstring, as pointed out by Julien Cornebise.
1 parent 72af8a4 commit fd1ddaf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,17 @@ def _gci(self):
12041204
helper for :func:`~matplotlib.pyplot.gci`;
12051205
do not use elsewhere.
12061206
"""
1207+
# Look first for an image in the current Axes:
1208+
cax = self._axstack.current_key_axes()[1]
1209+
if cax is None:
1210+
return None
1211+
im = cax._gci()
1212+
if im is not None:
1213+
return im
1214+
1215+
# If there is no image in the current Axes, search for
1216+
# one in a previously created Axes. Whether this makes
1217+
# sense is debatable, but it is the documented behavior.
12071218
for ax in reversed(self.axes):
12081219
im = ax._gci()
12091220
if im is not None:

0 commit comments

Comments
 (0)