我试图绘制一个颜色渐变,我希望沿着一个轴是均匀的(在下面由角度pi/7
定义的图片的情况下)
当我使用patch
命令时,绘图匹配所需的渐变方向,但沿着它不均匀(沿圆的点之间形成各种三角形)
这是代码
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
您必须定义Faces
property以确保颜色填充垂直于轴的条纹(请参阅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