Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color contour different than pcolor

Tags:

matlab

contour

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

like image 436
Matthias Pospiech Avatar asked Feb 15 '12 07:02

Matthias Pospiech


1 Answers

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

like image 123
Matthias Pospiech Avatar answered Sep 22 '22 14:09

Matthias Pospiech