使用由曲线函数定义的色彩图填充曲线下方的区域

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

考虑以下情节:

enter image description here

在左侧,您可以使用patch命令查看相对于函数轮廓的圆的填充

t = linspace(-pi,pi,100);
c = exp(-cos(t));
figure(1)
patch(cos(t),sin(t),c)
axis equal

在右侧,您可以看到左侧虚线轴上的功能配置文件,使用area命令填充该配置文件。

figure(2)
area(cos(t),c,0);

我要做的是用左侧面板中表示的colormap定义的颜色填充曲线下方的区域(右侧面板)。结果应该像这样enter image description here

matlab plot colors matlab-figure area
1个回答
1
投票

我能想出的最接近的是:

function q55322965
% Evaluate the equation (half domain!)
t = linspace(-pi,0,50);
c = exp(-cos(t));

% Turn vectors into a mesh:
[TT,CC] = meshgrid(cos(t),c);

% Clear all points that are above the curve:
CC(CC > c) = NaN;

% Fill in the rectangle between the chart and zero:
CC(end+1,:) = 0;
TT(end+1,:) = TT(end,:);

% Plot:
figure(); mesh(TT,CC,CC,'FaceColor','interp','EdgeColor','interp'); view([0,90]);

产量:

enter image description here

如果您在使用此方法绘图时想要较少的锯齿状外观,则可以在t中增加分辨率。例如,如果我们在500中使用50而不是linspace,我们得到:

enter image description here

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