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

Matlab 如何用使用不同颜色贴图的等高线图覆盖pcolor图?,matlab,plot,contour,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 这显示了灰度彩色地图中的等高线图和伪彩色图。然而,我想要实现的只是将轮廓变成灰色 这只

无法实现此目标的最低示例:

[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
这显示了灰度彩色地图中的等高线图和伪彩色图。然而,我想要实现的只是将轮廓变成灰色


这只是一个简单的例子,实际上等高线图是由不同的数据组成的,具有不同的范围,因此也需要两个独立的
caxis
设置。

您可以通过连接两个彩色地图来解决问题,并确保函数的值能够访问colormap的正确部分:

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)


要获得更方便的解决方案,您可能还需要查看

相关:谢谢。但是,如果函数范围相差几个数量级,则必须小心。我还将查看您链接的to@TobiasKienzler:是的,正确地缩放数据/彩色贴图可能会很棘手。此外,如果数据提示没有显示正确的值,这可能会很烦人。我的解决方案实际上是一种变通方法。