Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB and high quality EPS figures

Tags:

matlab

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.

like image 967
jtromans Avatar asked Nov 26 '11 19:11

jtromans


People also ask

Can Matlab open EPS files?

TeX cannot render EPS files. These are different languages. The TeX compiler can convert TeX to EPS (usually with the intermediate step of a DVI).

How do you improve the quality of a plot in Matlab?

It is possible to increase the resolution of the plots obtained in MATLAB. On the Plot window ---- Click on <Edit> --> <Figure properties> --> <Export setup> --> <Rendering>. Then change the resolution to 300 or 600dpi.

How do I save a Figure as a EPS in Matlab?

Save Figure as EPS FileCreate a bar chart and save it as an EPS file. Specify the 'epsc' driver to save it in color. saveas saves the bar chart as Barchart.

What is EPS in Matlab?

d = eps returns the distance from 1.0 to the next larger double-precision number, that is, 2-52. example. d = eps( x ) , where x has data type single or double , returns the positive distance from abs(x) to the next larger floating-point number of the same precision as x .


3 Answers

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.

like image 102
David_G Avatar answered Oct 22 '22 16:10

David_G


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.

like image 35
Egon Avatar answered Oct 22 '22 17:10

Egon


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.

like image 11
user664303 Avatar answered Oct 22 '22 17:10

user664303