I am looking to export my MATLAB plot as a high quality figure. Specifically, I would like to save it as a vector based file format such as EPS or SVG.
I hav
Matlab can export to pdf with better quality than EPS, but with its own caveats of setting decent margins and font sizes.
edit: Examples are similar to the EPS case as explained in the help of e.g. print:
saveas(gcf,'filename.pdf')
or
print('-dpdf','filename.pdf')
You might also want to take a look at the PaperSize
, PaperPosition
and PaperUnits
properties of your figure (by means of the set
and get
functions).
edit: Another option is to use one of the functions available on FileExchange such as the ones mentioned by @user664303 below. My personal favorite for use with LaTeX is matlab2tikz for which the latest version can be gotten from GitHub. Together with the external library of TikZ, I think this delivers some of the most nicest graphs around.
Probably it's also best to mention that I have been actively involved in the matlab2tikz
project since 2012.
I always acquire the final plots (those which are supposed to be inserted into papers and publications) by matplotlib
library of python
.
You can bet on the amazing quality of the generated plots, both .pdf
and .eps
formats.
I thought I would share the issue I had, and how I overcame it...
I was getting terrible results because I had the wrong renderer set to default. In my startup.m
, I had the zbuffer
renderer enabled. This is an example eps output.
I made that eps output with: print(gcf,'-depsc2','filename.eps')
. This eps is so OBVIOUSLY rasterised. It makes me angry at matlab. Then, I had a brainwave - perhaps my default renderer zbuffer
is interfering with the image save process. So, adding the line:
set(gcf,'renderer','painters')
and running the print command as before, here is the output:
Note that I just took screenshots of the eps output files at 100%. And I can confirm the second image is actually vector. Here is a good question/explanation on choosing Renderers in MATLAB.
The export_fig function on the MATLAB file exchange is a reasonably reliable way of accurately exporting figures to eps and pdf (as well as bitmap formats) in MATLAB.
The plot2svg function, also from the file exchange, allows you to export in svg format. It provides some additional benefits, such as being able to export translucent patch objects in vector format.
A comparison of exporting methods is given in this blog post.