Matlab 如何更改轮廓图在 z 轴上的位置 [英] Matlab how to change contourf plot's location on z axis

查看:74
本文介绍了Matlab 如何更改轮廓图在 z 轴上的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a 3d surface in my figure surf(x,y,z)

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

I also have a contourf surface (which is basically a 2D plane).

我将它们绘制在同一个图中,但 contourf 图自动处于 z=0 级别.我想将 contourf 图移动到 z=-10(或 z 轴上的任何值),但我做不到.

I plot them in the same figure but the contourf plot is automatically at z=0 level. I want to move the contourf plot to z=-10 (or any value on z-axis) but I can't do it.

我确信这很容易,但我在 MATLAB 帮助/谷歌中找不到答案.有什么想法吗?

I am sure it is easy but I can't find the answer in MATLAB help/Google. Any ideas?

推荐答案

考虑以下示例:

%# 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

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

The above doesn't work anymore in HG2. It can be fixed using a hidden property of contours ContourZLevel:

Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z);
h.ContourZLevel = -10;

您也可以使用 hgtransform实现类似的事情,这是记录和推荐的方法.

You can also use hgtransform to achieve a similar thing, which is the documented and recommended approach.

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

See another answer of mine for further explanation: plot multiple 2d contour plots in one 3d figure.

这篇关于Matlab 如何更改轮廓图在 z 轴上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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