def from_mpl(fig, savefig_kw=None):
    """Create a SVG figure from a ``matplotlib`` figure.

    Parameters
    ----------
    fig : matplotlib.Figure instance

    savefig_kw : dict
         keyword arguments to be passed to matplotlib's
         `savefig`



    Returns
    -------
    SVGFigure
        newly created :py:class:`SVGFigure` initialised with the string
        content.


    Examples
    --------

    If you want to overlay the figure on another SVG, you may want to pass
    the `transparent` option:

    >>> from svgutils import transform
    >>> import matplotlib.pyplot as plt
    >>> fig = plt.figure()
    >>> line, = plt.plot([1,2])
    >>> svgfig = transform.from_mpl(fig,
    ...              savefig_kw=dict(transparent=True))
    >>> svgfig.getroot()
    <svgutils.transform.GroupElement object at ...>


    """

    fid = StringIO()
    if savefig_kw is None:
        savefig_kw = {}

    try:
        fig.savefig(fid, format='svg', **savefig_kw)
    except ValueError:
        raise(ValueError, "No matplotlib SVG backend")
    fid.seek(0)
    fig = fromstring(fid.read())

    # workaround mpl units bug
    w, h = fig.get_size()
    fig.set_size((w.replace('pt', ''), h.replace('pt', '')))

    return fig
def from_mpl ( fig , savefig_kw = None ) : fid = StringIO ( ) if savefig_kw is None : savefig_kw = { } try : fig . savefig ( fid , format = 'svg' , ** savefig_kw ) except ValueError : raise ( ValueError , "No matplotlib SVG backend" ) fid . seek ( 0 ) fig = fromstring ( fid . read ( ) ) w , h = fig . get_size ( ) fig . set_size ( ( w . replace ( 'pt' , '' ) , h . replace ( 'pt' , '' ) ) ) return fig
Create a SVG figure from a ``matplotlib`` figure.

    Parameters
    ----------
    fig : matplotlib.Figure instance

    savefig_kw : dict
         keyword arguments to be passed to matplotlib's
         `savefig`



    Returns
    -------
    SVGFigure
        newly created :py:class:`SVGFigure` initialised with the string
        content.


    Examples
    --------

    If you want to overlay the figure on another SVG, you may want to pass
    the `transparent` option:

    >>> from svgutils import transform
    >>> import matplotlib.pyplot as plt
    >>> fig = plt.figure()
    >>> line, = plt.plot([1,2])
    >>> svgfig = transform.from_mpl(fig,
    ...              savefig_kw=dict(transparent=True))
    >>> svgfig.getroot()
    <svgutils.transform.GroupElement object at ...>