如何在MATLAB中填充3D图形下方的区域? [英] How can I fill an area below a 3D graph in MATLAB?

查看:297
本文介绍了如何在MATLAB中填充3D图形下方的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用功能plot3在MATLAB中创建了以下3d图:

I created the following 3d plot in MATLAB using the function plot3:

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

Now, I want to get a hatched area below the "2d sub-graphs" (i.e. below the blue and red curves). Unfortunately, I don't have any idea how to realize that.

如果有人有一个主意,我将非常感激.

I would appreciate it very much if somebody had an idea.

推荐答案

您可以使用 fill3 并引用此二维情况的答案以了解您的情况在数据向量的末端添加点以封闭"填充的多边形.尽管即使不是不可能也很难创建图案(即阴影线),但是另一种方法是简单地调整填充色块的Alpha透明度.这是一个补丁的简单示例:

You can do this using the function fill3 and referencing this answer for the 2D case to see how you have to add points on the ends of your data vectors to "close" your filled polygons. Although creating a pattern (i.e. hatching) is difficult if not impossible, an alternative is to simply adjust the alpha transparency of the filled patch. Here's a simple example for just one patch:

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组数据的示例:

You can also create multiple patches in one call to fill3. Here's an example with 4 sets of data:

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

这是它的情节:

这篇关于如何在MATLAB中填充3D图形下方的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆