How to remove lines when saving fill plot

3 views (last 30 days)
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,
Kevin

Accepted Answer

Image Analyst
Image Analyst on 20 Jul 2013
Try a different rendering engine, or see the FAQ
  1 Comment
Kevin
Kevin 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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!