颜色轮廓与pcolor不同

5

我正在使用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中的颜色为灰度值,轮廓线为彩色。但是这样我也需要一个轮廓线的图例。

编辑: 通过组合两个colormap,它以某种方式起作用,但是此时颜色栏显示了两者,这不是我想要的。我更希望有一个颜色栏,其中包含与绘图相同的轮廓线。

[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');

编辑: 可以通过以下方式更正colorbar:

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

enter image description here


你的代码缺少 zlevs 的定义(并且有一个小错别字)。 - Itamar Katz
我已经修复了打字错误。但是如果有任何关于如何使轮廓线条与绘图不同颜色的最小提示,都将非常有帮助。 - Matthias Pospiech
@MatthiasPospiech:colorbar实际上是一个坐标轴。您可以更改其任何属性,例如x/y限制、颜色限制、位置等。您还可以模拟colorbar或添加额外的colorbar,将其创建为单独的pcolor/imagesc图。 - yuk
@yuk:我该如何获取色条的轴,或者说我该如何获取任何图形的轴句柄? - Matthias Pospiech
你已经有了它。它是 hcb。所以你可以这样做:set(hcb,'ylim',[0 1])。当前轴的句柄是 gca。一般来说,查看你正在使用的图形函数的文档,它通常可以返回轴句柄。 - yuk
1个回答

5

除了在问题中提出的解决方案之外,还可以使用工具freezeColorsCOLORMAP和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;

enter image description here


我在使用cbfreez时遇到了问题。我正在尝试在这里使用您的例程,但是出现了以下错误:??? Error using ==> colormap at 56 First argument must be a scalar axes handle.Error in ==> cbfreeze at 332 cmap = colormap(fig);Error in ==> testcolorbar at 18 cbfreeze; - user1331843

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接