在Matlab 2014b中移动等高线图的z值

时间:2014-11-29 15:45:58

标签: matlab plot contour

我正在尝试制作表面图的图形,并且在表面下方我希望显示轮廓线,但我希望轮廓位于z = -1而不是默认值{{1 }}。我找到了关于此问题here的上一篇文章,但是当我尝试解决方案时,轮廓仍在0。也许它与我正在使用的MATLAB版本有关,这是2014b? 关于如何使其发挥作用的任何想法?

我试过的代码:

z = 0

3 个答案:

答案 0 :(得分:0)

所以,我无法按照我发现和发布的示例中提出的那样去做,但我发现了一种有效的方法。我最终做的基本上是这样的:

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));

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

答案 1 :(得分:0)

我想出了如何解决用户Kine面临的颜色映射问题。注意:我在MATLAB R2015b上完成了以下代码:

offset = 0.5;
plotHandle = surfc(X1, Y1, Z1);
hold on;
% This line moves the surface up from its original location and increases the space between the surface and the contour plot
plotHandle(1).ZData = plotHandle.ZData + offset;
% However in doing so the color mappings are changed. So, the line below restores these mappings
plotHandle(1).CData = plotHandle.CData - offset;

% This line changes fills the contour plot
plotHandle(2).Fill = 'on';
grid on;

% The following lines draw critical areas on the contour line, as it was more readable in my case
axisHandle = gca;
ZHeight = axisHandle.ZLim(1);
plot3(X2, Y2, ZHeight, 'o', 'MarkerSize', 10, 'LineWidth', 1, 'Color', 'k', 'MarkerFaceColor', 'm');
plot3(Y2, X2, ZHeight, 'o', 'MarkerSize', 10, 'LineWidth', 1, 'Color', 'k', 'MarkerFaceColor', 'm');

hold off

答案 2 :(得分:0)

我遇到了同样的问题。 最后,我得到了平面Z = -10的contourf。 我的MATLAB版本是

MATLAB版本:8.5.0.197613(R2015a)

希望代码可以帮助您

clear all
clc

[X,Y,Z] = peaks;

[~,hContour] = contourf(X,Y,Z,20,'edgecolor','none');

hContour.ContourZLevel = -10; % set the contour's Z position

view(44,30)

colormap(jet)