如何使用使用不同色彩图的等高线图覆盖pcolor图?

Tob*_*ler 7 matlab plot contour

无法实现的最小示例:

[X,Y,Z] = peaks;
figure;
pcolor(X,Y,Z);
shading flat;
hold all;
axes;
contour(X,Y,Z);
colormap gray;  % this should only apply to the contour plot axes...
axis off;       % ... but it doesn't
Run Code Online (Sandbox Code Playgroud)

这显示了灰度色彩图中的等高线图和伪色图.但是,我想要实现的只是将轮廓变成灰色.

这只是一个简约的例子,实际上轮廓图是具有不同范围的不同数据,因此caxis也需要两个独立的设置.

Jon*_*nas 5

您可以通过连接两个色彩映射来确定问题,并确保函数的值使得它们可以访问色彩映射的正确部分:

cm = [jet(64);gray(64)];
figure,
pcolor(X,Y,Z)
shading flat
hold on
%# Z in the contour starts after the maximum
%# of Z in pcolor
contour(X,Y,Z-min(Z(:))+max(Z(:))+2,'LineWidth',2)
%# apply the colormap
colormap(cm)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

为了更方便的解决方案,您可能还想查看本周的文件交换选择