Matlab如何在z轴上改变contourf plot的位置

the*_*emy 7 3d matlab plot z-axis

我的身材中有一个3d表面 surf(x,y,z)

我也有一个contourf表面(基本上是一个2D平面).

我在相同的图中绘制它们,但contourf绘图自动处于z=0水平.我想将contourf绘图移动到z=-10(或z轴上的任何值),但我不能这样做.

我相信这很容易但我在MATLAB help/Google中找不到答案.有任何想法吗?

Amr*_*mro 10

请考虑以下示例:

%# plot surface and contour
Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z);       %# get handle to contourgroup object

%# change the ZData property of the inner patches
hh = get(h,'Children');    %# get handles to patch objects
for i=1:numel(hh)
    zdata = ones(size( get(hh(i),'XData') ));
    set(hh(i), 'ZData',-10*zdata)
end
Run Code Online (Sandbox Code Playgroud)

截图


更新:

以上在HG2中不再起作用.它可以使用轮廓的隐藏属性来修复ContourZLevel:

Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z);
h.ContourZLevel = -10;
Run Code Online (Sandbox Code Playgroud)

您还可以使用hgtransform实现类似的东西,这是记录和推荐的方法.

请参阅我的另一个答案以获得进一步的解释:在一个三维图中绘制多个2d等高线图.