颜色轮廓不同于pcolor

时间:2012-02-15 07:51:28

标签: matlab contour

我正在使用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');

enter image description here

我更希望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]);

enter image description here

1 个答案:

答案 0 :(得分:5)

除了问题中已经提供的解决方案之外,还可以使用工具freezeColorsCOLORMAP and COLORBAR utilities在单个数字中更改色彩映射

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