Skip to content

Commit 9eee66f

Browse files
authored
Merge pull request #15201 from anntzer/autogcai
Autogenerate gca(), gci() from boilerplate.py.
2 parents 88bebf0 + de05af1 commit 9eee66f

File tree

3 files changed

+28
-47
lines changed

3 files changed

+28
-47
lines changed

lib/matplotlib/figure.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,21 @@ def sca(self, a):
19691969
return a
19701970

19711971
def _gci(self):
1972+
# Helper for `~matplotlib.pyplot.gci`. Do not use elsewhere.
19721973
"""
1973-
Helper for :func:`~matplotlib.pyplot.gci`. Do not use elsewhere.
1974+
Get the current colorable artist.
1975+
1976+
Specifically, returns the current `.ScalarMappable` instance (`.Image`
1977+
created by `imshow` or `figimage`, `.Collection` created by `pcolor` or
1978+
`scatter`, etc.), or *None* if no such instance has been defined.
1979+
1980+
The current image is an attribute of the current axes, or the nearest
1981+
earlier axes in the current figure that contains an image.
1982+
1983+
Notes
1984+
-----
1985+
Historically, the only colorable artists were images; hence the name
1986+
``gci`` (get current image).
19741987
"""
19751988
# Look first for an image in the current Axes:
19761989
cax = self._axstack.current_key_axes()[1]

lib/matplotlib/pyplot.py

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -332,31 +332,6 @@ def rcdefaults():
332332
draw_all()
333333

334334

335-
## Current image ##
336-
337-
338-
def gci():
339-
"""
340-
Get the current colorable artist.
341-
342-
Specifically, returns the current `.ScalarMappable` instance (`.Image`
343-
created by `imshow` or `figimage`, `.Collection` created by `pcolor` or
344-
`scatter`, etc.), or *None* if no such instance has been defined.
345-
346-
The current image is an attribute of the current axes, or the nearest
347-
earlier axes in the current figure that contains an image.
348-
349-
Notes
350-
-----
351-
Historically, the only colorable artists were images; hence the name
352-
``gci`` (get current image).
353-
"""
354-
return gcf()._gci()
355-
356-
357-
## Any Artist ##
358-
359-
360335
# (getp is simply imported)
361336
@docstring.copy(_setp)
362337
def setp(obj, *args, **kwargs):
@@ -851,27 +826,6 @@ def sca(ax):
851826
raise ValueError("Axes instance argument was not found in a figure")
852827

853828

854-
def gca(**kwargs):
855-
"""
856-
Get the current :class:`~matplotlib.axes.Axes` instance on the
857-
current figure matching the given keyword args, or create one.
858-
859-
Examples
860-
--------
861-
To get the current polar axes on the current figure::
862-
863-
plt.gca(projection='polar')
864-
865-
If the current axes doesn't exist, or isn't a polar one, the appropriate
866-
axes will be created and then returned.
867-
868-
See Also
869-
--------
870-
matplotlib.figure.Figure.gca : The figure's gca method.
871-
"""
872-
return gcf().gca(**kwargs)
873-
874-
875829
## More ways of creating axes ##
876830

877831
@docstring.dedent_interpd
@@ -2339,6 +2293,18 @@ def figtext(
23392293
x, y, s, fontdict=fontdict, withdash=withdash, **kwargs)
23402294

23412295

2296+
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
2297+
@docstring.copy(Figure.gca)
2298+
def gca(**kwargs):
2299+
return gcf().gca(**kwargs)
2300+
2301+
2302+
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
2303+
@docstring.copy(Figure._gci)
2304+
def gci():
2305+
return gcf()._gci()
2306+
2307+
23422308
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
23432309
@docstring.copy(Figure.ginput)
23442310
def ginput(

tools/boilerplate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def boilerplate_gen():
177177
_figure_commands = (
178178
'figimage',
179179
'figtext:text',
180+
'gca',
181+
'gci:_gci',
180182
'ginput',
181183
'suptitle',
182184
'waitforbuttonpress',

0 commit comments

Comments
 (0)