recipes : Plotting : 2D Data : Artifacts in surface plots exported as EPS


When I export a surface plot as an EPS file it looks blurry or contains white diagonal lines. How do I avoid the white lines and/or get rid of the blur?


EPS files are nice because they are vector images, so they scale nicely, take up little room and produce nice printed graphics. The downside is that when you export surface plots they don't always look the way you might expect. Let's take an example.

shading flat
axis tight

When you run this code, what you see on the screen looks like this:

However, if you save this as an EPS file you instead see the following (note the white diagonals):

Although this looks rather ugly on-screen, most printers do not reproduce the white lines. The white lines won't be visible on all computers. Whether or not you see them will depend upon the program you use to display the images. But how to avoid the white lines in EPS plots? One way of getting around the problem is to use the imagesc command instead of pcolor.

axis xy %Needed to have the orientation be the same as the pcolor version

On many computers this will solve the problem. However, on the Mac there is an issue. The Mac PDF renderer is rather exuberant in its use of interpolation. Here's what it looks like on my Mac:

So on a Mac, MATLAB EPS files look blurry and terrible. It's smeared out the data and, what's worse, it even looks like this when you print. It doesn't matter which PDF viewer you use, they all seem to do it. If you disable anti-aliasing in the PDF viewer's preferences then the image looks good but the text looks terrible. Of course, disabling anti-aliasing is not an option in reality because you can't ask your readers to do this.

This is really frustrating, because even you don't use a Mac you may have readers of your document who do. You could make the image with pcolor but then you get white diagonal lines on most screens, although the printed version should be fine. At the moment, the only solution I know of is a nasty hack wherein we use imagesc on an up-sampled version of the image. Here goes:

P=padarray(P,[1,1],0,'both'); %padd the edges to avoid artefacts
P=interp2(P,4,'nearest'); %interpolate 
axis xy

This is obviously a major improvement over what we had before, although clearly we've added more pixels so the axis tick labels are different. This can be fixed if needed by altering the "XTickLabel" and "YTickLabel" properties of the axes. The main point is that now we have an EPS file that looks like the on-screen version.


It's clear there can be some issues with the way Matlab exports figures. To a large degree the problems you're seeing here are due to errors in the way the external rendering (viewing) programs handle EPS files. On some platforms the images look right and on others they look wrong. Nonetheless, the result is that the user must check the quality of the representation if the images are to be used for an important project. If you're preparing a file for publication then it might wise to check what it looks like on Windows, Mac, and Linux. Note, however, that you'll only need to do this if you're using EPS files. Raster formats, such as PNG, won't suffer from these problems. The downside of raster files is that they take up more room and may be compressed by the publisher which can result in plots with nasty compression artefacts.

Finally, if all else fails, you can try opening your EPS file in Inkscape, a free vector drawing package, then saving it again. This tends to clear up some EPS issues, such as fonts not being embedded.


Want to continue the discussion?
Enter your comments, suggestions, or thoughts below

comments powered by Disqus