Skip to content

Document how to check for the existence of current figure/axes. #20783

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
Aug 4, 2021
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
8 changes: 7 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,13 @@ def sca(self, a):
@docstring.dedent_interpd
def gca(self, **kwargs):
"""
Get the current Axes, creating one if necessary.
Get the current Axes.

If there is currently no Axes on this Figure, a new one is created
using `.Figure.add_subplot`. (To test whether there is currently an
Axes on a Figure, check whether ``figure.axes`` is empty. To test
whether there is currently a Figure on the pyplot figure stack, check
whether `.pyplot.get_fignums()` is empty.)

The following kwargs are supported for ensuring the returned Axes
adheres to the given projection etc., and for Axes creation if
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,10 @@ def gcf():
"""
Get the current figure.

If no current figure exists, a new one is created using
`~.pyplot.figure()`.
If there is currently no figure on the pyplot figure stack, a new one is
created using `~.pyplot.figure()`. (To test whether there is currently a
figure on the pyplot figure stack, check whether `~.pyplot.get_fignums()`
is empty.)
"""
manager = _pylab_helpers.Gcf.get_active()
if manager is not None:
Expand Down