如何用使用不同颜色图的轮廓图覆盖pcolor图? [英] How to overlay a pcolor plot with a contour plot that uses a different colormap?

查看:137
本文介绍了如何用使用不同颜色图的轮廓图覆盖pcolor图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法实现的最小示例:

[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

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

This shows both the contour plot and the pseudo colour plot in the grayscale colourmap. However, what I want to achieve is only turning the contours gray.

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

This is just a minimalistic example, in reality the contour plot is of different data that has a different range, so two independent caxis settings are required as well.

推荐答案

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

You can fix the problem by catenating two colormaps, and making sure that the values of the functions are such that they access the right part of the 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)

对于更方便的解决方案,您可能还想看看

For a more convenient solution, you may also want to have a look at this file exchange pick of the week

这篇关于如何用使用不同颜色图的轮廓图覆盖pcolor图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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