Exporting colored eps figures from Matlab

When you get stuck with Matlab, you find an answer to your problem usually in a reasonable amount of time – usually. Yesterday, I was really unlucky with the following.

My annoying problem was that (on a mac) color plots exported as eps, will be rendered with blurry edges. See left picture below. The right picture shows how my plot looks in Matlab and how I want it to be exported.

It was relatively easy to find people with a similar problem (here, or there) as well as an explanation for it: The culprit is the anti-aliasing rendering feature which is enabled in practically every eps viewer. So the problem is not Matlab itself, but rather how Matlab and the eps renderer are interacting. However, finding a working solution was hard. After one day of searching (and finally using Bing instead of Google search), I found a working solution in  this thread.

Here is the fix: In Matlab, in the Export setup under Rendering, you have to use the OpenGL renderer, not the standard painter. That’s it!

 

I prefer to save figures directly from the script where I also compose the plot in the first place. For doing this, just add the following line to your Matlab code:

plot(data);
set(gcf,'renderer','opengl'); % the magic line
saveas(gcf,'test.eps','epsc');

I’m happy to have solved the issue, but I am also starting to wonder about scientific plotting tool alternatives, such as python’s matplotlib or Gnuplot.

 

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.