def create_figure(*args, margin=False, **kwargs) -> 'Figure':
    """Create a independent figure.

    Different from the :func:`plt.figure`, the figure from this function won't
    be managed by matplotlib. And it has
    :obj:`matplotlib.backends.backend_agg.FigureCanvasAgg`, and therefore, you
    can use the ``canvas`` attribute to get access the drawn image.

    Args:
        *args: All positional arguments of :class:`matplotlib.figure.Figure`.
        margin: Whether to reserve the white edges of the figure.
            Defaults to False.
        **kwargs: All keyword arguments of :class:`matplotlib.figure.Figure`.

    Return:
        matplotlib.figure.Figure: The created figure.
    """
    from matplotlib.backends.backend_agg import FigureCanvasAgg
    from matplotlib.figure import Figure

    figure = Figure(*args, **kwargs)
    FigureCanvasAgg(figure)

    if not margin:
        # remove white edges by set subplot margin
        figure.subplots_adjust(left=0, right=1, bottom=0, top=1)

    return figure
Create a independent figure.

    Different from the :func:`plt.figure`, the figure from this function won't
    be managed by matplotlib. And it has
    :obj:`matplotlib.backends.backend_agg.FigureCanvasAgg`, and therefore, you
    can use the ``canvas`` attribute to get access the drawn image.

    Args:
        *args: All positional arguments of :class:`matplotlib.figure.Figure`.
        margin: Whether to reserve the white edges of the figure.
            Defaults to False.
        **kwargs: All keyword arguments of :class:`matplotlib.figure.Figure`.

    Return:
        matplotlib.figure.Figure: The created figure.
    
mmpretrain/visualization/utils.py