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

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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

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

*No products are associated with this question.*

Answer by Image Analyst on 20 Jul 2013

Accepted answer

Try a different rendering engine, or see the FAQ

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

## 0 Comments