5959from matplotlib import cbook
6060from matplotlib import _docstring
6161from matplotlib .backend_bases import FigureCanvasBase , MouseButton
62- from matplotlib .figure import Figure , figaspect
62+ from matplotlib .figure import Figure , FigureBase , figaspect
6363from matplotlib .gridspec import GridSpec , SubplotSpec
6464from matplotlib import rcParams , rcParamsDefault , get_backend , rcParamsOrig
6565from matplotlib .rcsetup import interactive_bk as _interactive_bk
@@ -690,7 +690,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
690690
691691 Parameters
692692 ----------
693- num : int or str or `.Figure`, optional
693+ num : int or str or `.Figure` or `.SubFigure` , optional
694694 A unique identifier for the figure.
695695
696696 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
702702 will be used for the ``Figure.number`` attribute, otherwise, an
703703 auto-generated integer value is used (starting at 1 and incremented
704704 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.
706707
707708 figsize : (float, float), default: :rc:`figure.figsize`
708709 Width, height in inches.
@@ -753,11 +754,11 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
753754 `~matplotlib.rcParams` defines the default values, which can be modified
754755 in the matplotlibrc file.
755756 """
756- if isinstance (num , Figure ):
757+ if isinstance (num , FigureBase ):
757758 if num .canvas .manager is None :
758759 raise ValueError ("The passed figure is not managed by pyplot" )
759760 _pylab_helpers .Gcf .set_active (num .canvas .manager )
760- return num
761+ return num . figure
761762
762763 allnums = get_fignums ()
763764 next_num = max (allnums ) + 1 if allnums else 1
0 commit comments