如何将 pcolor 图与使用不同颜色图的等高线图重叠?

发布于 2024-10-27 23:08:47 字数 346 浏览 3 评论 0原文

未实现此目的的最小示例:

[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 设置。

Minimum example that does not achieve it:

[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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-11-03 23:08:47

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

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)

在此处输入图像描述

要获得更方便的解决方案,您可能还需要查看 本周文件交换精选

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)

enter image description here

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文