Save figure SVG from Matlab or Matplotlib

Matlab or Matplotlib will save infinite resolution vector graphics SVG format, viewable in web browsers. SVG is usable by LaTeX.

  • vector graphics (SVG or EPS) allow nearly infinite zooming without loss of quality–excellent for line plots and contour plots
  • SVG is viewable by any web browser, and is usable from LaTeX
  • EPS is more commonly used in LaTeX
  • PNG is raster graphics, so has finite (blocky) resolution

Here are examples of saving figures to SVG from Matlab and Matplotlib.


To save figure handle fg, simply do fg.savefig('myfig.svg').

from pathlib import Path
from matplotlib.figure imoprt Figure

fn = Path('~/Documents/mycoolfig.svg').expanduser()

data = [1,2,3,4]

fg = Figure()
ax = fg.gca()

fg.savefig(fn, bbox_inches='tight')


Matlab figures in general are saved by exportgraphics.

data = [1,2,3,4]

fg = figure();

exportgraphics(fg, 'matfig.svg')