MATLAB Answers

## How to remove lines when saving fill plot

Asked by Kevin

### Kevin (view profile)

on 19 Jul 2013
Accepted Answer by Image Analyst

### Image Analyst (view profile)

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

https://www.dropbox.com/s/ho2t8hraphu610a/test1.pdf

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,

Kevin

## Products

No products are associated with this question.

## 1 Answer

### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 20 Jul 2013
Accepted answer

Try a different rendering engine, or see the FAQ

Kevin

### Kevin (view profile)

on 21 Jul 2013

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,

Kevin

#### Join the 15-year community celebration.

Play games and win prizes!

Learn more

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!