Jul 21, 2009

Produce Print-Quality Figures from Matlab

This post explains how to create print-quality figures in Matlab. The process is efficient and results in editable vector-graphics that you can include in any document including Microsoft Word, Open Office, or latex. Before you create your figures you might also want to check my article on combinations of linestyles and markers to have clear plots in black-and-white and color.


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


I 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 Matlab

For matlab, there is the package plot2svg, which allows you to export figures from matlab to SVG. In order to export your figure instead of exportfig(1,'filename.eps','width',5,'color','rgb'); you do plot2svg('filename.svg',1).

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:
  1. (matlab) export to svg
    >> plot2svg('filename.svg',1)
  2. edit in svg editor (e.g. inkscape), export to pdf
    inkscape -F filename.svg --export-pdf=filename.pdf
  3. convert pdf to eps
    convert filename.pdf filename.eps
This doesn't help with the font size problem yet. But you can automate the editing and conversion process, which reduces the problem considerably.
  1. 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.
  2. Convert from SVG to pdf: inkscape -f filename.svg --export-pdf=filename.pdf
  3. Convert from pdf to eps: convert filename.pdf filename.eps
Using this method, you'll have nearly same comfort as with matlab's copy-figure function in windows and get figures of much higher quality because of the vector format.

Alternative EPS Export

In 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. h=figure('position',[100 0 1100 1100],'paperpositionmode','auto', 'color','none','InvertHardcopy','off');
% plot something...
Enjoy. Please vote this post up if you liked it and leave a comment below for questions and suggestions. 


  1. That's one way to do it. I just print my figures directly to PDF, and they stay vector in that case.

  2. @Anonymous: The question is if you can edit your files comfortably. While SVG files are easy to edit, for pdf files I yet have to see a free editor (I am excluding adobe's pdf editors for the windows platform) that gives you the same comfort as you have with inkscape and the likes.

  3. @Anonymous: If you include transparency in any of your graphics in MATLAB, exporting to PDF will be done with the bitmap-based OpenGL renderer. In such situations, SVG appears to be the only option to export transparent vector graphics out of MATLAB.

    However, if you don't need transparency, MATLAB will allow you to adjust almost any of the graphics properties (line size, width, font size, font face, paper size, etc.) using Figure Properties and Axes Properties. The interface is a bit klunky, but there should be very little reason to use a third party editor on MATLAB graphics.

  4. @Anonymous: Thanks for your great explanation. I find transparency very important for figures, but I this is not the only reason I find SVG a great format for matlab export.

    I usually run matlab without java (needed for the figure editor), often in remote, and I don't want to fire up matlab every time I want to make changes to a figure. Inkscape is a very nice editor (not klunky at all, I think) and further the advantage of having a text-based format like SVG is that it allows application of regular expressions and many command line commands to automatically change many properties at once and even of many figures at the same time if necessary. This makes it very fast to get figures exactly the way you want them.

  5. Well I tried similar procedure on some wmf i.e. edited with Inkscape exported to pdf and than used the convert from ImageMagick tool. The result was dissapointing since all the lines were blurred - has anyone idea why that happend?

  6. @Anonymous: I suppose you convert from windows meta file (wmf) to pdf to eps. .wmfs can contain both vector and raster elements, so I am not sure how the inkscape wmf import works, but I assume that in inkscape the image doesn't look blurred. Have you looked at the pdf, does it look alright?

  7. Hi, I have a problem with plot2svg,
    when I magnify my plot in matlab(zoom in) and use the command plot2svg, still saves the same small figure from matlab, and in svg magnifying it to the degree that I need does not contain the details. how can I convert the zoomed in image to svg?

  8. Hi guys, when I am actually willing of reading these blog post to be updated regularly. It offers fastidious stuff.
    cheap brochure printing

  9. You're so cool! I do not believe I've truly read through a single thing like that before.
    So great to discover somebody with a few unique thoughts on this
    topic. Seriously.. many thanks for starting this up. This web
    site is something that's needed on the web, someone with
    a little originality!

    Also visit my site - car repair spring hill

  10. It's an amazing piece of writing in favor of all the online viewers;
    they will obtain benefit from it I am sure.

    my website ... bizzboard.com

  11. Hi to all, the blog has really the dreadful information I really enjoyed a lot.Laserscan Lytham

  12. Kebocoran pre-ejakulasi berasal penis pria ketika mereka terangsang, dan pre-ejakulasi dapat mengandung sperma, yang dapat menyebabkan kehamilan :
    minyak lintah papua
    obat aborsi paling manjur
    Banyak perempuan yang belum siap hamil dengan bermacam alasan. Untuk menghindari kehamilan yang tak terduga, perempuan banyak yang melakukan aneka cara usai bersenggama.

  13. thank you for sharing of some of the articles we read this one article is very interesting for us, i like it dildo and very helpful to me cara menghilangkan tato permanen

  14. Leave Packing and Moving to Best Packers and Movers in Ghaziabad

    Packers and Movers Delhi @ http://3th.co.in/packers-and-movers-delhi/
    Packers and Movers Faridabad @ http://3th.co.in/packers-and-movers-faridabad/
    Packers and Movers Ghaziabad @ http://3th.co.in/packers-and-movers-ghaziabad/
    Packers and Movers Noida @ http://3th.co.in/packers-and-movers-noida/

  15. How did you can avail the experts services of listed Adword India's No 1 companies?
    Thanks for information visit: http://www.adword.co.in/

  16. Exoprt Packers and Movers India are known to provide moving and packing services at the rates that actually fit in your budget and make you local shifting solutions experts for amazing rather than being filth only.
    Packers and Movers in Pune
    Packers and Movers in Mumbai
    Packers and Movers in Hyderabad
    Packers and Movers in Bangalore
    Packers and Movers in Chennai

  17. Get a wide range of packing and moving companies at helloenquiry.in. We endeavour to furnish the best packers and movers companies in Bhubaneswar at ease of Internet. Packers and Movers Bhubaneswar

  18. Really impressive post. I read it whole and going to share it with my social circules. I enjoyed your article and planning to rewrite it on my own blog.
    Packers And Movers Bangalore

  19. Their notoriety is broke down by the arrangements they offer so try not to be worried about the security perspective any more as you will be put hold of the best specialists as it were. Additionally, our moving organizations and packers in Chennai are likewise low on your value go and will cost the little costs that you have ever anticipated.
    Packers And Movers Tuticorin Thoothukudi Tamilnadu
    Packers And Movers Vellore Tamilnadu

  20. I deeply appreciate the information

  21. terimakasih pencerahannya, sekarang saya bisa mengatur waktu tidur saya setalah membaca artikel cara mengatur waktu tidur . cara mengatasi wifi limited access

  22. All the best blogs that is very useful for keeping me share the ideas
    of the future as well this is really what I was looking for, and I am
    very happy to come here. Thank you very much
    earn to die
    earn to die 2
    earn to die 3
    Hi! I’ve been reading your blog for a while now and finally got the
    earn to die 4
    courage to go ahead and give youu a shout out from
    earn to die 6
    Austin Texas! Just wanted to tell
    earn to die 5
    Hi! I’ve been reading your blog for a while now and finally got the
    happy wheels
    strike force heroes
    you keep up the fantastic work!my weblog
    age of war
    earn to die 5
    good game empire

  23. This comment has been removed by the author.

  24. Are you need the best moneylender in singapore here is the list of website

    moneylender in singapore
    licensed moneylender

  25. The information you have posted is very useful. The sites you have referred was good. Thanks for sharing..


  26. شركة تنظيف بالمدينة المنورة
    تعد المدينة المنورة من ارقى مناطق المملكة و تتميز بالطابع الدافئ والتواصل بين سكانها واجتماعهم في المناسبات المختلفه من هنا جاءت اهمية شركة تنظيف بالمدينة المنورة لتقديم خدمات التنظيف للبيوت والمنازل والفلل والقصور
    ولاننا ندرك بان الفلل تحتاج الى عمالة مدربة على تنظيف الاماكن الواسعة فالاول لمهارة عمالها تعد افضل شركة تنظيف فلل بالمدينة المنورة تتميز بسرعة اداء عمالها في تقديم خدمة تنظيف فلل بالمدينة المنورة نتميز باننا افضل شركات تنظيف الفلل بالمدينة المنورة
    وكثيرا ما تحتوى الفلل على عدة خزانات فلابد من الاستعانة بافضل شركة تنظيف خزانات بالمدينة المنورة فهى تستخدم افضل منظفات الخزانات والمطهرات نتميز باننا احسن شركة غسيل خزانات بالمدينة المنورة نغسل كافة انواع خزانات مياه الشرب بالمدينة
    ولاننا افضل شركة تنظيف شقق بالمدينة المنورة نقدم افضل خدمة تنظيف شقق بالمدينة المنورة بالاعتماد على افضل منظفات الكنب والستائر بالبخار
    وكثيرا ما يحتاج سكان المدينة المنورة الى شركة نقل اثاث لنقل الاثاث من المدينة المنورة الى اى مكان داخل او خارج المملكة من هنا جاءت اهمية افضل شركة نقل اثاث بالمدينة المنورة تستخدم افضل سيارات نقل العفش المخصصة لهذا الغرض من هنا استحقت الاول افضل شركة نقل عفش بالمدينة المنورة
    شركة تنظيف شقق بالقطيف

    شركة نقل اثاث بينبع -
    شركة عزل خزانات بالرياض


    تعتبر تسربات المياه من احد المشكلات التى لابد ان نقوم بحلها على الفور لان تسربات المياه تؤدى الى عدد كبير من المشكلات نحن فى غنى عنها فالاول شركة كشف تسربات المياه بالمدينة المنورة تعتمد على افضل الاجهزه والالات المخصصه باعمال الكشف عن تسربات المياه فلا داعى للقلق من شان التسربات على الاطلاق فتذكر عزيزى العميل ان شركة كشف تسربات المياه بالمدينة المنورةعلى اتم استعداد للوصول الى اى مكان بالمدينة او خارج المدينة للقيام بالكشف عن تسربات المياه

  27. Considering over the reasons of this monster fan taking after that WordPress has ended up being constantly; we go over some stunning segments and inspirations driving interest that are select just to WordPress. On the off chance that you are an administrator and wish to have a strong website page that web crawlers love, then PSD to WordPress change is the decision you ought to make! Need to analyze more about the supernatural occurrences WordPress can do to your business site?

    PSD to Wordpress Conversion
    PDF to Wordpress Conversion
    PNG to Wordpress Conversion
    JPG to Wordpress Conversion

  28. This is one of the cult game now, a lot of people enjoy playing them . Also you can refer to the game :
    gold mine strike | pokemon go 2
    The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
    stickman games | stick war 2 | animal jam 2