在Matlab 2014b中移动等高线图的z值 [英] Shift the z -value of contour plot in Matlab 2014b

查看:85
本文介绍了在Matlab 2014b中移动等高线图的z值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制表面图,并希望在表面下方显示轮廓线,但我希望轮廓位于z = -1而不是默认值0.我在此处上找到了以前的帖子,但是当我尝试解决方案时,轮廓仍为z = 0.也许与我正在使用的MATLAB版本(2014b)有关? 关于如何使它起作用的任何想法?

I'm trying to make a figure of a surface plot, and beneath the surface I wish to show the contour lines, but I want the contour to be at z = -1 instead of at the default value 0. I found a previous post about this problem here, but when I try the solution the contour is still at z = 0. Maybe it has something to do with the version of MATLAB I'm using, which is 2014b? Any ideas on how to make it work?

我尝试的代码:

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

推荐答案

因此,我无法真正确定要按照我发现并发布的示例中的建议进行操作,但是我找到了一种可行的方法.我最终要做的基本上是这样:

So, I couldn't really figure out to do it as proposed in the example I found and posted, but I found a way that works. What I ended up doing was basically this:

figure
hold on
surf(X,Y,Z+1);
contour(X,Y,Z);
zz = get(gca,'ZTick');
set(gca,'ZTickLabel',sprintf('%3.1f\n',zz-1));

这使我在同一张图中获得了冲浪和轮廓,但是在颜色映射方面产生了一些问题.

This gets me the surf and contour in the same figure, but yields some problems with color mappings.

这篇关于在Matlab 2014b中移动等高线图的z值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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