Skip to content

Autogenerate gca(), gci() from boilerplate.py. #15201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,21 @@ def sca(self, a):
return a

def _gci(self):
# Helper for `~matplotlib.pyplot.gci`. Do not use elsewhere.
"""
Helper for :func:`~matplotlib.pyplot.gci`. Do not use elsewhere.
Get the current colorable artist.

Specifically, returns the current `.ScalarMappable` instance (`.Image`
created by `imshow` or `figimage`, `.Collection` created by `pcolor` or
`scatter`, etc.), or *None* if no such instance has been defined.

The current image is an attribute of the current axes, or the nearest
earlier axes in the current figure that contains an image.

Notes
-----
Historically, the only colorable artists were images; hence the name
``gci`` (get current image).
"""
# Look first for an image in the current Axes:
cax = self._axstack.current_key_axes()[1]
Expand Down
58 changes: 12 additions & 46 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,31 +332,6 @@ def rcdefaults():
draw_all()


## Current image ##


def gci():
"""
Get the current colorable artist.

Specifically, returns the current `.ScalarMappable` instance (`.Image`
created by `imshow` or `figimage`, `.Collection` created by `pcolor` or
`scatter`, etc.), or *None* if no such instance has been defined.

The current image is an attribute of the current axes, or the nearest
earlier axes in the current figure that contains an image.

Notes
-----
Historically, the only colorable artists were images; hence the name
``gci`` (get current image).
"""
return gcf()._gci()


## Any Artist ##


# (getp is simply imported)
@docstring.copy(_setp)
def setp(obj, *args, **kwargs):
Expand Down Expand Up @@ -851,27 +826,6 @@ def sca(ax):
raise ValueError("Axes instance argument was not found in a figure")


def gca(**kwargs):
"""
Get the current :class:`~matplotlib.axes.Axes` instance on the
current figure matching the given keyword args, or create one.

Examples
--------
To get the current polar axes on the current figure::

plt.gca(projection='polar')

If the current axes doesn't exist, or isn't a polar one, the appropriate
axes will be created and then returned.

See Also
--------
matplotlib.figure.Figure.gca : The figure's gca method.
"""
return gcf().gca(**kwargs)


## More ways of creating axes ##

@docstring.dedent_interpd
Expand Down Expand Up @@ -2339,6 +2293,18 @@ def figtext(
x, y, s, fontdict=fontdict, withdash=withdash, **kwargs)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@docstring.copy(Figure.gca)
def gca(**kwargs):
return gcf().gca(**kwargs)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@docstring.copy(Figure._gci)
def gci():
return gcf()._gci()


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@docstring.copy(Figure.ginput)
def ginput(
Expand Down
2 changes: 2 additions & 0 deletions tools/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def boilerplate_gen():
_figure_commands = (
'figimage',
'figtext:text',
'gca',
'gci:_gci',
'ginput',
'suptitle',
'waitforbuttonpress',
Expand Down