MATLAB Answers


How to remove lines when saving fill plot

Asked by Kevin
on 19 Jul 2013

I am trying to plot a polygon with the coloring shaded with respect to a separate function. See code below taken from ``Area plot with gradient"--Patrick Kalita's answer on 16 Feb 2011:

% Define x, f(x), and M(x)
x = linspace(0, 2*pi, 20)';
f = cos(x) + 2;
M = x.^2;
% Define the vertices: the points at (x, f(x)) and (x, 0)
N = length(x);
verts = [x(:), f(:); x(:) zeros(N,1)];
% Define the faces to connect each adjacent f(x) and the corresponding points at y = 0.
q = (1:N-1)';
faces = [q, q+1, q+N+1, q+N];
p = patch('Faces', faces, 'Vertices', verts, 'FaceVertexCData', [M(:); M(:)], 'FaceColor', 'interp', 'EdgeColor', 'none')

If I save or print the image:

print -dpdf -r600 test1.pdf

I get lines going through the plot. See the figure here

Does anyone have a fix for this, or a reason why it happens? I've tried setting the patch so that there is only one face. The problem seems to be set in the 'interp' FaceColor. I've also tried setting the children edge color to none:

set(get(p,'children'), 'edgecolor', 'none')

however, this doesn't help.

Thank you,



Log in to comment.

1 Answer

Answer by Image Analyst
on 20 Jul 2013
 Accepted Answer

Try a different rendering engine, or see the FAQ

  1 Comment

Thank you very much for the suggestion. After I downloaded the export_fig function, I realized the problem was still occurring. In the documentation with the function I read the issue is caused by the anti-aliasing of the pdf viewer I am using. Turning off the anti-aliasing or viewing the pdf in another program fixes my issue.

Thank you again,


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today