Showing posts with label colorbar. Show all posts
Showing posts with label colorbar. Show all posts

Sunday, February 05, 2012

How to have two colormaps in MATLAB plots?

A very useful and nice tool to achieve multiple colormaps in MATLAB plots (By John Iversen):

http://www.mathworks.com/matlabcentral/fileexchange/7943

Sample example where the subgraph and the larger graphs have different colormaps:

Thursday, February 24, 2011

MEEP colormap for Matlab

I have been thinking of using the colormap used in the MEEP software (an open source FDTD code) as a nice alternative to the classical Matlab colormap. Here is the short Matlab code to generate it and the resulting images:

mincolor    = [1 0 0]; % red
mediancolor = [1 1 1]; % white   
maxcolor    = [0 0 1]; % blue      

ColorMapSize = 4;
int1 = zeros(ColorMapSize,3); 
int2 = zeros(ColorMapSize,3);
for k=1:3
    int1(:,k) = linspace(mincolor(k), mediancolor(k), ColorMapSize);
    int2(:,k) = linspace(mediancolor(k), maxcolor(k), ColorMapSize);
end
meep = [int1(1:end-1,:); int2];

colormap(meep); 
colorbar
Classical Matlab colormap (jet)
MEEP colormap with ColorMapSize 64
MEEP colormap with ColorMapSize 16
MEEP colormap with ColorMapSize 4

*Images are snapshots from the FDTD simulation of a dish antenna.

caxis and colorbar in Matlab


If colorbar is used before the caxis, the colorbars show the original image limits. Thus, colorbars are not accurate
When the colorbar is used after caxis. This time the colorbars are accurate.

When using caxis with pcolor in Matlab, colorbar does not update if it is defined before caxis is called. The remedy is basically use colorbar whenever a new axis limit is defined by caxis. The sample code given in Matlab's manual is modified as follows to handle the issue of interest.


figure (1); clf; 
load cape
colormap(map)
subplot(2,2,1)
image(X,'CDataMapping','scaled');  
axis image
title('Caxis = [1 192]'); colorbar;
subplot(2,2,2)
image(X,'CDataMapping','scaled')
axis image
title('Caxis = [20 192]');  
caxis([20 192]); 
colorbar;  % Should be introduced after the caxis is employed
subplot(2,2,3)
image(X,'CDataMapping','scaled')
axis image
title('Caxis = [50 192]');  
caxis([50 192]); 
colorbar;
subplot(2,2,4)
image(X,'CDataMapping','scaled')
axis image
title('Caxis = [100 192]');  
caxis([100 192]); colorbar;