通过颜色渐变补丁圈

问题描述 投票:3回答:1

我试图绘制一个颜色渐变,我希望沿着一个轴是均匀的(在下面由角度pi/7定义的图片的情况下)

当我使用patch命令时,绘图匹配所需的渐变方向,但沿着它不均匀(沿圆的点之间形成各种三角形)

enter image description here

这是代码

N=120;
theta = linspace(-pi,pi,N+1);
theta = theta(1:end-1);
c = exp(-6*cos(theta-pi/7));
figure(1)
patch(cos(theta),sin(theta),c)
ylabel('y'); xlabel('x')
axis equal
matlab plot matlab-figure
1个回答
5
投票

您必须定义Facesproperty以确保颜色填充垂直于轴的条纹(请参阅Specifying Faces and Vertices)。否则,MATLAB将使用一些算法将颜色尽可能平滑地混合。

N=120;
a = pi/7;

theta = linspace(a,2*pi+a,N+1); % note that I changed the point sequence, this is just to make it easier to produce the matrix for Faces.
theta(end) = [];

ids = (1:N/2)';
faces = [ids, ids+1, N-ids, N-ids+1];

c = exp(-6*cos(a-theta))';

figure
patch('Faces', faces, 'Vertices',[cos(theta);sin(theta)]','FaceVertexCData',c, 'FaceColor', 'interp', 'EdgeColor', 'none')
ylabel('y'); xlabel('x')
axis equal

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.