Skip to content

Commit fe82c30

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

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎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 `.add_subplot`. (To test whether there is currently an Axes on
1491+
a Figure, check whether ``figure.axes`` is empty. To test whether
1492+
there is currently a Figure on the pyplot figure stack, check whether
1493+
`.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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,8 @@ def gcf():
820820
Get the current figure.
821821
822822
If no current figure exists, a new one is created using
823-
`~.pyplot.figure()`.
823+
`~.pyplot.figure()`. (To test whether a current figure exists, check
824+
whether `~.pyplot.get_fignums()` is empty.)
824825
"""
825826
manager = _pylab_helpers.Gcf.get_active()
826827
if manager is not None:

0 commit comments

Comments
 (0)