颜色轮廓与 pcolor 不同

发布于 2025-01-05 22:26:58 字数 1122 浏览 0 评论 0原文

我将 pcolor 与轮廓线一起使用。但是,无法从图中识别线条的值,如下图所示。

[x y data] = peaks(1000);
data = data / max(max(data));

colorDepth = 1000;
colormap(jet(colorDepth));

hold on;
pcolor(x,y,data); shading flat

[C,hfigc] = contour(x, y, data,[0:0.1:1]);
set(hfigc, ...
    'LineWidth',1.0, ...
    'Color', [1 1 1]);
hold off;
hcb = colorbar('location','EastOutside');

在此处输入图像描述

我宁愿希望 pcolor 为灰度值,轮廓线为彩色。然而,我还需要轮廓线的图例。

编辑: 它以某种方式通过组合两个颜色图来工作,但随后颜色条显示两者,这不是我想要的。我宁愿想要一个包含与绘图相同的轮廓线的颜色条。

[x y data] = peaks(1000);
data = data - min(min(data));
data = data / max(max(data));

colorDepth = 1000;

hold on;
caxis([-1 1]);
colormap([gray(colorDepth); jet(colorDepth)]);
hplot = pcolor(x,y,data); shading flat        

[C,hfigc] = contour(x, y, data-1,[-1:0.1:0]);
set(hfigc, 'LineWidth',1.0);
% set(hfigc, 'Color', [1 1 1]);

hold off;
hcb = colorbar('location','EastOutside');

编辑: 来校正颜色条

set(hcb, 'Ylim', [0 1]);

可以使用在此处输入图像描述

I am using pcolor together with contour lines. However, the value of the lines can not be identified from the plot, as can be seen in the following picture.

[x y data] = peaks(1000);
data = data / max(max(data));

colorDepth = 1000;
colormap(jet(colorDepth));

hold on;
pcolor(x,y,data); shading flat

[C,hfigc] = contour(x, y, data,[0:0.1:1]);
set(hfigc, ...
    'LineWidth',1.0, ...
    'Color', [1 1 1]);
hold off;
hcb = colorbar('location','EastOutside');

enter image description here

I would rather want the pcolor to be in gray values and the contour lines in colors. However then I need a legend for the contour lines as well.

EDIT:
It works somehow by combining two colormaps, but then the colorbar shows both, which is not what I want. I would rather want to have a colorbar which includes the same contour lines as the plot.

[x y data] = peaks(1000);
data = data - min(min(data));
data = data / max(max(data));

colorDepth = 1000;

hold on;
caxis([-1 1]);
colormap([gray(colorDepth); jet(colorDepth)]);
hplot = pcolor(x,y,data); shading flat        

[C,hfigc] = contour(x, y, data-1,[-1:0.1:0]);
set(hfigc, 'LineWidth',1.0);
% set(hfigc, 'Color', [1 1 1]);

hold off;
hcb = colorbar('location','EastOutside');

EDIT:
The colorbar can be corrected with

set(hcb, 'Ylim', [0 1]);

enter image description here

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

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

发布评论

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

评论(1

临走之时 2025-01-12 22:26:58

除了问题中已经提出的解决方案之外,还可以使用工具 freezeColors 和 COLORMAP 和 COLORBAR 实用程序,用于更改单个图中的颜色图

addpath('cm_and_cb_utilities');
addpath('freezeColors');

figure(1); clf;
[x y data] = peaks(1000);
data = data - min(min(data));
data = data / max(max(data));

colorDepth = 1000;

hold on;
caxis([0 1]);
colormap(jet(colorDepth));
hplot = pcolor(x,y,data); shading flat        

hcb = colorbar('location','EastOutside');
set(hcb, 'Ylim', [0 1]);
cbfreeze;

freezeColors;

colormap(gray(colorDepth));
[C,hfigc] = contour(x, y, data,[0:0.1:1]);
set(hfigc, 'LineWidth',1.0);

hold off;

在此处输入图像描述

Besides the solution presented already in the question it is possible to use the tools freezeColors and COLORMAP and COLORBAR utilities to change the colormap in a single figure

addpath('cm_and_cb_utilities');
addpath('freezeColors');

figure(1); clf;
[x y data] = peaks(1000);
data = data - min(min(data));
data = data / max(max(data));

colorDepth = 1000;

hold on;
caxis([0 1]);
colormap(jet(colorDepth));
hplot = pcolor(x,y,data); shading flat        

hcb = colorbar('location','EastOutside');
set(hcb, 'Ylim', [0 1]);
cbfreeze;

freezeColors;

colormap(gray(colorDepth));
[C,hfigc] = contour(x, y, data,[0:0.1:1]);
set(hfigc, 'LineWidth',1.0);

hold off;

enter image description here

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