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');
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]);
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With