jar*_*ead 3 matlab plot matlab-figure
我正在尝试绘制一个我希望沿轴均匀的颜色渐变(在下面的图片中,由角度定义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
Run Code Online (Sandbox Code Playgroud)
您必须定义Faces
属性以确保颜色填充垂直于轴的条纹(请参见指定面和顶点)。否则,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
Run Code Online (Sandbox Code Playgroud)