from io import StringIO


def figure_to_svg(fig):
    """Convert a figure to svg for inline display."""
    fc = fig.get_facecolor()
    ec = fig.get_edgecolor()
    fig.set_facecolor('white')
    fig.set_edgecolor('white')
    try:
        string_io = StringIO()
        fig.canvas.print_figure(string_io, format='svg')
        svg = string_io.getvalue()
    finally:
        fig.set_facecolor(fc)
        fig.set_edgecolor(ec)
    return svg