code: def fig_to_svg(fig):
      
      buf = io.StringIO()
      fig.savefig(buf, format='svg')
      buf.seek(0)
      return buf.getvalue()
docs: Helper function to convert matplotlib figure to SVG string
  
      Returns:
          str: figure as SVG string