Skip to content

Commit 5d74a71

Browse files
committed
Document how to check for the existence of current figure/axes.
1 parent e291cdb commit 5d74a71

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/matplotlib/figure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,13 @@ def sca(self, a):
14841484
@docstring.dedent_interpd
14851485
def gca(self, **kwargs):
14861486
"""
1487-
Get the current Axes, creating one if necessary.
1487+
Get the current Axes.
1488+
1489+
If there is currently no Axes on this Figure, a new one is created
1490+
using `.Figure.add_subplot`. (To test whether there is currently an
1491+
Axes on a Figure, check whether ``figure.axes`` is empty. To test
1492+
whether there is currently a Figure on the pyplot figure stack, check
1493+
whether `.pyplot.get_fignums()` is empty.)
14881494
14891495
The following kwargs are supported for ensuring the returned Axes
14901496
adheres to the given projection etc., and for Axes creation if

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,10 @@ def gcf():
819819
"""
820820
Get the current figure.
821821
822-
If no current figure exists, a new one is created using
823-
`~.pyplot.figure()`.
822+
If there is currently no figure on the pyplot figure stack, a new one is
823+
created using `~.pyplot.figure()`. (To test whether there is currently a
824+
figure on the pyplot figure stack, check whether `~.pyplot.get_fignums()`
825+
is empty.)
824826
"""
825827
manager = _pylab_helpers.Gcf.get_active()
826828
if manager is not None:

0 commit comments

Comments
 (0)