code: def fig2x(figure, format):
      
  
      # Save svg to file like object svg_io
      io = StringIO()
      figure.savefig(io, format=format)
  
      # Rewind the file like object
      io.seek(0)
  
      data = io.getvalue()
      io.close()
  
      return data
docs: Returns svg from matplotlib chart