clear
clf
disp('Next we show how to present two subplots in different colors')
disp('by using colorbar4 routine')
disp('This example uses <label_style> routine')
disp('Press any key')
pause
disp('--------------')
subplot(121)
[cc,hh]=contourf(peaks(50)); clabel(cc,hh); axis square
%retriev contour_levels
clevs=colorbar4(gca);

%assign all colors to white
cols=ones(length(clevs),3);

%find indices corresponding to clevs<-2 and clevs>=2
ind1=find(clevs<-2);
ind2=find(clevs>=2);

%negative values - aquamarine; positive yellow-green
cols(ind1,:)=([1:length(ind1)]'/length(ind1)*0.5+0.5)*[0 1 1];
cols(ind2,:)=([length(ind2):-1:1]'/length(ind2)*0.5+0.5)*[1 1 0];

%change colors and draw the colorbar
colorbar4(gca,cols,1);
label_style

subplot(122)
[cc,hh]=contourf(peaks(50)); clabel(cc,hh); axis square
%retriev contour_levels
clevs=colorbar4(gca);

%assign all colors to white
cols=ones(length(clevs),3);

%find indices corresponding to clevs<-2 and clevs>=2
ind1=find(clevs<-2);
ind2=find(clevs>=2);

%negative values - blue; positive red
cols(ind1,:)=([1:length(ind1)]'/length(ind1)*0.5+0.5)*[0 0 1];
cols(ind2,:)=([length(ind2):-1:1]'/length(ind2)*0.5+0.5)*[1 0 0];

%change colors and draw the colorbar
colorbar4(gca,cols,1);
label_style
disp('--------------')
disp('Next example shows how do we manage colors when the levels')
disp('in contourf plot are defined')
disp('Press any key')
pause

clf
disp('--------------')
clevs=[-6 -2 0 2 6]
[cc,hh]=contourf(peaks(50),clevs); clabel(cc,hh); 
ccols=[0.6 1 1 0.8 0.9] 
disp('the colors above are gray scale, so we don''t need the triples of [RGB]')
disp('Press any key')
pause
colorbar4(gca,ccols,1);

disp('--------------')
disp('We have a white hole in the area below -6 because minimum of array smaller than')
disp('minimal level. We add additional level, say -100')
clevs=[-100 clevs]
disp('Press any key')
pause
clf
[cc,hh]=contourf(peaks(50),clevs); clabel(cc,hh); 
levs=colorbar4(gca);
levs
disp('As you can see, Matlab adds additional level corresponding to the array minimum')
disp('We overcome this by setting the equal colors to the two lowest levels')
ccols=[0.4 0.4 0.6 1 1 0.8 0.9] 
disp('Press any key')
pause
colorbar4(gca,ccols,1);

disp('--------------')
label_style