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

    """Creates a new figure.
    Parameters
    num : integer or string, optional, default: none
    If not provided, a new figure will be created, and the figure number
    will be incremented. The figure objects holds this number in a `number`
    attribute.
    If num is provided, and a figure with this id already exists, make
    it active, and returns a reference to it. If this figure does not
    exists, create it and returns it.
    If num is a string, the window title will be set to this figure\s
    `num`.
    figsize : tuple of integers, optional, default: None
    width, height in inches. If not provided, defaults to rc
    figure.figsize.
    dpi : integer, optional, default: None
    resolution of the figure. If not provided, defaults to rc figure.dpi.
    facecolor :
    the background color. If not provided, defaults to rc figure.facecolor.
    edgecolor :
    the border color. If not provided, defaults to rc figure.edgecolor.
    frameon : bool, optional, default: True
    If False, suppress drawing the figure frame.
    FigureClass : class derived from matplotlib.figure.Figure
    Optionally use a custom Figure instance.
    clear : bool, optional, default: False
    If True and the figure already exists, then it is cleared.
    Returns
    figure : Figure
    The Figure instance returned will also be passed to new_figure_manager
    in the backends, which allows to hook custom Figure classes into the
    pylab interface. Additional kwargs will be passed to the figure init
    function.
    Notes
    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.
    rcParams defines the default values, which can be modified in the
    matplotlibrc file
    """
    if (figsize is None):
        figsize = rcParams[u'figure.figsize']
    if (dpi is None):
        dpi = rcParams[u'figure.dpi']
    if (facecolor is None):
        facecolor = rcParams[u'figure.facecolor']
    if (edgecolor is None):
        edgecolor = rcParams[u'figure.edgecolor']
    allnums = get_fignums()
    next_num = ((max(allnums) + 1) if allnums else 1)
    figLabel = u''
    if (num is None):
        num = next_num
    elif isinstance(num, six.string_types):
        figLabel = num
        allLabels = get_figlabels()
        if (figLabel not in allLabels):
            if (figLabel == u'all'):
                warnings.warn(u"close('all')    closes    all    existing    figures")
            num = next_num
        else:
            inum = allLabels.index(figLabel)
            num = allnums[inum]
    else:
        num = int(num)
    figManager = _pylab_helpers.Gcf.get_fig_manager(num)
    if (figManager is None):
        max_open_warning = rcParams[u'figure.max_open_warning']
        if ((max_open_warning >= 1) and (len(allnums) >= max_open_warning)):
            warnings.warn((u'More    than    %d    figures    have    been    opened.    Figures    created    through    the    pyplot    interface    (`matplotlib.pyplot.figure`)    are    retained    until    explicitly    closed    and    may    consume    too    much    memory.    (To    control    this    warning,    see    the    rcParam    `figure.max_open_warning`).' % max_open_warning), RuntimeWarning)
        if (get_backend().lower() == u'ps'):
            dpi = 72
        figManager = new_figure_manager(num, figsize=figsize, dpi=dpi, facecolor=facecolor, edgecolor=edgecolor, frameon=frameon, FigureClass=FigureClass, **kwargs)
        if figLabel:
            figManager.set_window_title(figLabel)
            figManager.canvas.figure.set_label(figLabel)
        def make_active(event):
            _pylab_helpers.Gcf.set_active(figManager)
        cid = figManager.canvas.mpl_connect(u'button_press_event', make_active)
       ...