IntroductionThere are serveral ways to export figures from matlab for a publication. In Windows, in the figure menu in matlab you choose to copy the figure to clipboard and then edit it in powerpoint or word any figure property you like. After that you paste them to your word document. On Linux you would usually export to EPS to get highest quality images.
EPS offers potentially the best quality images, however it brings problems especially with font size, figure size, and transparency. Increasing font sizes might overlay multiple layers of the same text. The bounding box is often messed up and you might want transparency. Laprint, an export tool for matlab, is a work-around for the font size problem, however legends do not get exported correctly and the figures still miss transparency. In this post I discuss a way to produce high-quality figures avoiding all those problems.
One way around the problems with Matlab is not using Matlab. GNU R produces very high quality figures, however R also has its own limitations. How to get the right font size and transparency with Matlab? Don't worry, there is a good solution that gives high quality figures.
SVGI just rediscovered the SVG format. It is really easy to retouch EPS images or import SVGs. SVG, short for scalable vector graphics, is a XML-based file format for two-dimensional vector graphics. This makes it really easy to read the files and edit them from the command line using sed, grep, awk, etc.
Why should you learn to use a vector format? Because the quality is very high!
If you export your matlab figure to EPS the problem is then to edit the image files. If you edit them with a raster editor, for example the gimp the quality gets completely lost. In contrast if you export from matlab to SVG, you edit your SVG file with inkscape or one of the other editors, similar to any desktop publishing tool. You can directly change line attributes, change text, and change the bounding box very comfortably.
There are free vector graphic editors with functionality similar to Adobe InDesign such as inkscape, and many other tools to edit and create SVGs, including OpenOffice, Xfig, scribus. gnuplot. Konqueror, Firefox, and, since recently, Internet Explorer can display SVGs. Editing of SVGs in Inkscape offers all comforts of a modern desktop publishing tool. See this Inkscape tutorial for more info about editing.
SVG in MatlabFor matlab, there is the package plot2svg, which allows you to export figures from matlab to SVG. In order to export your figure instead of
There are small caveats to using inkscape that bring complications, which however can be easily overcome. If you export directly with inkscape to eps, transparent colors might get black, you don't see anything. This also occurs when exporting to Latex (pdftricks).
There is a solution: convert the edited SVG first to PDF and then convert from pdf to eps using e.g. ImageMagick. You can integrate eps figures with most word processors and it would be the default image format with latex (texi2dvi).
Breakdown so far:
- (matlab) export to svg
- edit in svg editor (e.g. inkscape), export to pdf
inkscape -F filename.svg --export-pdf=filename.pdf
- convert pdf to eps
convert filename.pdf filename.eps
- Change font size:
sed -i "/font-size/s/[0-9][0-9]*pt/14pt/g" filename.svg. In this case, you would change your font size to 11pt.
- Convert from SVG to pdf:
inkscape -f filename.svg --export-pdf=filename.pdf
- Convert from pdf to eps:
convert filename.pdf filename.eps
Alternative EPS ExportIn a comment to my post LaTex Poster Template, Marcus vLW pointed out a method for exporting to EPS from matlab, which impressed me a lot, so I want to reshare his method here. It seems to give proper transparency.
% plot something...