59
59
from matplotlib import cbook
60
60
from matplotlib import _docstring
61
61
from matplotlib .backend_bases import FigureCanvasBase , MouseButton
62
- from matplotlib .figure import Figure , figaspect
62
+ from matplotlib .figure import Figure , FigureBase , figaspect
63
63
from matplotlib .gridspec import GridSpec , SubplotSpec
64
64
from matplotlib import rcParams , rcParamsDefault , get_backend , rcParamsOrig
65
65
from matplotlib .rcsetup import interactive_bk as _interactive_bk
@@ -690,7 +690,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
690
690
691
691
Parameters
692
692
----------
693
- num : int or str or `.Figure`, optional
693
+ num : int or str or `.Figure` or `.SubFigure` , optional
694
694
A unique identifier for the figure.
695
695
696
696
If a figure with that identifier already exists, this figure is made
@@ -702,7 +702,8 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
702
702
will be used for the ``Figure.number`` attribute, otherwise, an
703
703
auto-generated integer value is used (starting at 1 and incremented
704
704
for each new figure). If *num* is a string, the figure label and the
705
- window title is set to this value.
705
+ window title is set to this value. If num is a ``SubFigure``, its
706
+ parent ``Figure`` is activated.
706
707
707
708
figsize : (float, float), default: :rc:`figure.figsize`
708
709
Width, height in inches.
@@ -753,11 +754,11 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
753
754
`~matplotlib.rcParams` defines the default values, which can be modified
754
755
in the matplotlibrc file.
755
756
"""
756
- if isinstance (num , Figure ):
757
+ if isinstance (num , FigureBase ):
757
758
if num .canvas .manager is None :
758
759
raise ValueError ("The passed figure is not managed by pyplot" )
759
760
_pylab_helpers .Gcf .set_active (num .canvas .manager )
760
- return num
761
+ return num . figure
761
762
762
763
allnums = get_fignums ()
763
764
next_num = max (allnums ) + 1 if allnums else 1
0 commit comments