tunar
tunar

Reputation: 189

White lines in figure after exporting to PDF

A 2D data matrix was plotted in MATLAB 2016a using contour (the first Figure below), and then I saved as the figure in the *.emf format. Next, I inserted the figure (emf) into a MS word document. And finally, the word document was converted to a pdf file.

I found that there are many white lines in the figure (when in a pdf format) as shown in the second figure below. My question is how can I remove those white lines?

Figure 1 Figure 2

The code is attached here:

path = 'C:\Users\Administrator\Desktop\';
data = importdata([path, 'lsa2.txt'], ' ', 6);
cdata = data.data;
n = 25;
contourf(cdata,n, 'LineStyle', 'none');
colormap(jet);
axis equal;

The data can be accessed here: https://www.dropbox.com/s/hzf75qiju6zsy9i/lsa2.txt?dl=0

Upvotes: 1

Views: 1739

Answers (1)

Dev-iL
Dev-iL

Reputation: 24169

As I mentioned in my comment, this is a bug with the way MATLAB exports graphics, as explained by Yair Altman and Dene Farrell:

I discovered that these white line artifacts happen when the painters renderer is used ... [which] is the default rendering [format engine] for vectorized (EPS/PDF) formats.

There are two separate issues with the Matlab export:

1. The main thing that everyone notices is that patches are broken up into triangles, each of which is a separate path object if inspected in illustrator.

2. Matlab sometimes adds extraneous 'cropping paths' that create an apparent white line even when there is no issue with fractured paths.

One workaround suggested there by ambramson is the following:

1. Save the figure as an .eps file (using the print command).
2. Using a text editor, change the line in the eps header from:

/f/fill ld

to:

/f{GS 1 LW S GR fill}bd

and move the line down several lines, to right below the /LW/setlinewidth ld line.
From here, your eps file should display fine on all pdf viewers.

Upvotes: 4

Related Questions