human
Complete this python program:
def figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=Figure, **kwargs):
assistant
#Here is the Python code you requested.

    """call signature::
    figure(num=None, figsize=(8, 6), dpi=80, facecolor=\w\, edgecolor=\k\)
    Create a new figure and return a :class:`matplotlib.figure.Figure`
    instance.  If *num* = *None*, the figure number will be incremented and
    a new figure will be created.  The returned figure objects have a
    *number* attribute holding this number.
    If *num* is an integer, and ``figure(num)`` already exists, make it
    active and return the handle to it.  If ``figure(num)`` does not exist
    it will be created.  Numbering starts at 1, matlab style::
    figure(1)
    If you are creating many figures, make sure you explicitly call "close"
    on the figures you are not using, because this will enable pylab
    to properly clean up the memory.
    Optional keyword arguments:
    Keyword     Description
    figsize     width x height in inches; defaults to rc figure.figsize
    dpi         resolution; defaults to rc figure.dpi
    facecolor   the background color; defaults to rc figure.facecolor
    edgecolor   the border color; defaults to rc figure.edgecolor
    rcParams defines the default values, which can be modified in the
    matplotlibrc file
    *FigureClass* is a :class:`~matplotlib.figure.Figure` or derived
    class that will be passed on to :meth:`new_figure_manager` in the
    backends which allows you to hook custom Figure classes into the
    pylab interface.  Additional kwargs will be passed on to your
    figure init function.
    """
    if (figsize is None):
        figsize = rcParams['figure.figsize']
    if (dpi is None):
        dpi = rcParams['figure.dpi']
    if (facecolor is None):
        facecolor = rcParams['figure.facecolor']
    if (edgecolor is None):
        edgecolor = rcParams['figure.edgecolor']
    if (num is None):
        allnums = [f.num for f in _pylab_helpers.Gcf.get_all_fig_managers()]
        if allnums:
            num = (max(allnums) + 1)
        else:
            num = 1
    else:
        num = int(num)
    figManager = _pylab_helpers.Gcf.get_fig_manager(num)
    if (figManager is None):
        if (get_backend().lower() == 'ps'):
            dpi = 72
        figManager = new_figure_manager(num, figsize=figsize, dpi=dpi, facecolor=facecolor, edgecolor=edgecolor, frameon=frameon, FigureClass=FigureClass, **kwargs)
        def make_active(event):
            _pylab_helpers.Gcf.set_active(figManager)
        cid = figManager.canvas.mpl_connect('button_press_event', make_active)
        figManager._cidgcf = cid
        _pylab_helpers.Gcf.set_active(figManager)
        figManager.canvas.figure.number = num
    draw_if_interactive()
    return figManager.canvas.figure