jtromans
jtromans

Reputation: 4263

MATLAB and high quality EPS figures

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 have tried print and saveas commands:
saveas(h,'myFileName','epsc2');
print('-r150','-depsc2', 'myFilename');

On all occasions this produces poor quality parts of the graph, although the axis-labels are indeed vector. Why does MatLab do some horrible rendering before putting it into an EPS?

Example of poor quality plot here: http://users.ox.ac.uk/~pemb2372/myFileName.eps

Edit: It is also worth noting that if you use a Mac viewing an EPS file from Matlab, 'Preview' app may render inner graph content rasterized and poor quality, while leaving the axis and labels vectorized and high quality. This is very misleading but when you open said EPS file in, for example, Inkscape, the quality is actually vector and quite high.

Edit 2: My university hosting account has expired, so you can no longer view the figure. Suffice it to say that it showed a poor quality raster-style plot within high quality beautiful axis lines, ticks and labels.

Upvotes: 15

Views: 48127

Answers (4)

Egon
Egon

Reputation: 4787

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.

Upvotes: 11

user1393214
user1393214

Reputation:

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.

Upvotes: 0

David_G
David_G

Reputation: 1157

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.

Crop of output eps

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:

Crop of second output eps

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.

Upvotes: 14

user664303
user664303

Reputation: 2063

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.

Upvotes: 11

Related Questions