如何在 MATLAB 中填充 3D 图形下方的区域?

How can I fill an area below a 3D graph in MATLAB?

我使用函数 plot3:

在 MATLAB 中创建了以下 3d 图

现在,我想在“2d 子图”下方(即蓝色和红色曲线下方)获得阴影区域。不幸的是,我不知道如何实现这一点。

如果有人有想法,我将不胜感激。

您可以使用函数 fill3 and referencing this answer for the 2D case 执行此操作,以了解如何将数据向量末端的点添加到 "close" 填充的多边形。虽然创建图案(即阴影线)即使不是不可能也很困难,但另一种方法是简单地调整填充补丁的 alpha 透明度。这是一个仅针对一个补丁的简单示例:

x = 1:10;
y = rand(1, 10);
hFill = fill3(zeros(1, 12), x([1 1:end end]), [0 y 0], 'b', 'FaceAlpha', 0.5);
grid on

下面是情节:

您还可以在对 fill3 的一次调用中创建多个补丁。这是一个包含 4 组数据的示例:

nPoints = 10;  % Number of data points
nPlots = 4;    % Number of curves
data = rand(nPoints, nPlots);  % Sample data, one curve per column

% Create data matrices:
[X, Y] = meshgrid(0:(nPlots-1), [1 1:nPoints nPoints]);
Z = [zeros(1, nPlots); data; zeros(1, nPlots)];
patchColor = [0 0.4470 0.7410];  % RGB color for patch edge and face

% Plot patches:
hFill = fill3(X, Y, Z, patchColor, 'LineWidth', 1, 'EdgeColor', patchColor, ...
              'FaceAlpha', 0.5);
set(gca, 'YDir', 'reverse', 'YLim', [1 nPoints]);
grid on

下面是情节: