White line etching on exported .eps figures in R2014b

When I create a filled contour map in R2014b, export to a .eps file, and then use this in a PDF (for example importing into a PDF created by LaTeX, or just using the Linux command convert fig.eps fig.pdf), the image in the PDF is etched with white lines. When I create exactly the same figure and follow the same process (export to .eps, import or convert to PDF) in R2014a or earlier versions, the image quality is perfectly fine. The white lines mostly go away if I switch the renderer from painters to opengl, but then of course it's not a true vector graphic and the resulting image is grainy.
This problem occurs on both my school computer (Red Hat), my home computer (Ubuntu), and my friend's computer (Mac).
I can reproduce this problem with the following commands in R2014b:
z = peaks; v = [min(z(:)) -6:8]; contourf(z,v); colormap('jet');
print(gcf,'-depsc','-painters','R2014b_painters.eps');
Running the same commands in R2014a on the same computer, the image quality is fine and there are no white lines in the .eps or .pdf.

Answers (4)

Hi, updating to R2016a, I encountered also the 'white lines' problem when printing filled contours to eps.
I modified the prologue of the eps file, replacing
/f/fill ld
by
/f{GS 1 LW S GR fill}bd
moving the line a bit further down, so that GS LW GR are all defined. Now the path of the patch is not only filled but a small outline is drawn around it which fills the gaps.

4 Comments

This worked for me, thanks a lot!!
Hi Elmar, where is prologue of the eps file please?
In each eps file created, there is a section defining some shortcut postscript commands. This is the prologue.
I also replaced the xmlgraphics-commons.jar by compiling a version with a modified eps header, but gave it up due to version conflicts.
Hi Elmar, thanks a lot for providing this fix. It works nicely.
My only problem is that it also seems to increase the fontweight of the axis labels in the figure. Any idea how to prevent this?

Sign in to comment.

Jan Pecka
Jan Pecka on 14 Jun 2017
Edited: Jan Pecka on 14 Jun 2017
After a bit of research, I found this fix. It works great both for print() and hgexport(). https://github.com/Conclusio/matlab-epsclean
Jan
Jan on 28 Dec 2014
Edited: Jan on 18 Oct 2015
Many artifacts in PDFs are not caused by Matlab but by the settings of the PDF viewer. PDF is a 2D format and the smooth visualization of 3D patches requires tricks. So try to solve this inside the PDF viewer at first. See http://www.mathworks.com/matlabcentral/answers/15388-artifacts-in-figures-exported-as-pdf-from-matlab .
[EDITED] See this blog about the problems of polytopes intersecting in 3D.

5 Comments

thanks Jan - opening the file in chrome showed this was a viewer issue for me.
This is absolutely ridiculous. I cannot create publication quality .eps figures, which severely limits the value of MATLAB. Mathworks needs to address this issue NOW. And I don't buy all the garbage about it being an image viewer issue. I run the same code with r2014a and I don't have the issue. In r2014b+, .eps files are not being saved properly.
Jan, the link to the blog did not make it.
Hi, I created a script to fix images like the one created with the command in the question. It is located here:
I hope it might help the Matlab developers to fix this problem (since the "bug" is present in literally every PDF viewer I tried) or that it might be of help to people who want to create nice EPS figures.
I thought I'd post it here because this was the first post I found when trying to find a solution.
This might be a very late comment but I just ran into this issue after updating to a newer version of MATLAB.
Previous commenters are right, this is a bug in MATLAB's new renderer (HG2) which was introduced in MATLAB R2014b.
There is a very lengthy thread discussing this issue in export_fig's github: (GitHub - export_fig) Lines on Patch-Objects after *.EPS/PDF export - e.g. with contourf #44

Sign in to comment.

I'm using Linux and I solve the problem with:
  1. Export/Save Figure as a jpg file with appropriate dpi. I achieve good results with 700 dpi. But well, play around.
  2. Use convert and pdfcrop (optional) command from the ImageMagick suite.
convert input-file.jpg [options] output-file.pdf #jpg to pdf
pdfcrop output-file.pdf cropped-file.pdf #Tight borders

Categories

Products

Asked:

on 11 Dec 2014

Answered:

on 9 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!