## 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.

## Python

To save figure handle `fg`

, simply do `fg.savefig('myfig.svg')`

.

```
from pathlib import Path
from matplotlib.pyplot import figure, draw
fn = Path('~/Documents/mycoolfig.svg').expanduser()
data = [1,2,3,4]
fg = figure()
ax = fg.gca()
ax.plot(data)
draw() # necessary to render figure before saving
fg.savefig(fn, bbox_inches='tight')
```

## Matlab

Matlab figures in general are saved by exportgraphics.

```
data = [1,2,3,4]
fg = figure();
plot(data)
exportgraphics(fg, 'matfig.svg')
```