function cols=m_colmap(nme,m,ncol)
% M_COLMAP Useful colormaps
% M_COLMAP(NAME) returns an M-by-3 matrix containing the NAME colormap
% where NAME is one of:
% 'jet' : a perceptually uniform variation of the JET colormap. It
% contains the multiple colours which make JET useful, while
% avoiding the weird highlighting especially around yellow and
% cyan. The colors begin with dark blue, range through shades
% of blue, green, orange and red, and ends with dark red.
% 'blue' : a perceptually useful blue shading (good for bathymetry)
% 'green' : a perceptually useful green shading
% 'diverging' : a blue/red diverging colormap
% 'odv' : an isoluminant map
% 'land' : a topographic height (green-brown-white) shading
% 'water' : blue shading for water (goes with 'land').
% 'gland' : a topographic height shading with more green
% 'bland' : a topographic height shading with browns only.
%
% and M is the same length as the current figure's colormap. If no
% figure exists, the length of the default colormap is used. The
% length can be explicitly specified with M_COLMAP(NAME,M)
%
% M_COLMAP(NAME,'step') returns a 256-color map in which colours are
% perceptually bunched into 16 separate colours. This is useful
% if you want to see "edges" in what would be an otherwise
% smooth gradation (i.e. approaching the look of contouring).
%
% M_COLMAP(NAME,'demo') Gives a demo of this behavior
%
% M_COLMAP(NAME,'step',M) bunches into M colours.
%
% The jet and odv colourmaps were designed using the CET Perceptually
% Uniform Colour Maps toolbox at peterkovesi.com/projects/colourmaps/
%
% The blue, green, and diverging colormaps are from CBREWER, a matlab
% implementation of colours described at http://colorbrewer2.org.
%
% The land and gland colormaps are derived from the ETOPO1 water/land
% colormap at soliton.vm.bytemark.co.uk/pub/cpt-city/ngdc/index.html
%
% See also PARULA, HSV, HOT, PINK, FLAG, COLORMAP, RGBPLOT.
% R Pawlowicz Nov/2017
% names
if nargin==0
m_colmap('get');
return;
end
switch lower(nme(1:3))
case 'jet'
nme='jet';
case 'blu'
nme='blue';
case 'gre'
nme='green';
case 'div'
nme='diverging';
case 'odv'
nme='odv';
case 'lan'
nme='land';
case 'wat'
nme='water';
case 'gla'
nme='gland';
case 'bla'
nme='bland';
case 'get'
fprintf('Colormaps include:\n');
fprintf(' ''jet'' {,M|,''step''{,M}}\n');
fprintf(' ''blue'' {,M|,''step''{,M}}\n');
fprintf(' ''green'' {,M|,''step''{,M}}\n');
fprintf(' ''diverging'' {,M|,''step''{,M}}\n');
fprintf(' ''land'' {,M|,''step''{,M}}\n');
fprintf(' ''gland'' {,M|,''step''{,M}}\n');
fprintf(' ''bland'' {,M|,''step''{,M}}\n');
fprintf(' ''water'' {,M|,''step''{,M}}\n');
otherwise
error(['map: ' mfilename ':invalidMapname'],...
' First argument must be an valid colormap name ');
end
if nargin < 2
f = gcf;
m = size(get(f,'Colormap'),1);
ncol=m;
else
if isnumeric(m)
ncol=m;
else
switch m(1:3)
case 'dem' % demo
clf;
subplot(2,1,1);
imagesc(peaks(10*10));
title('Peaks function displayed with IMAGESC');
subplot(2,1,2);
imagesc(1:256);
cols=m_colmap(nme,'step');
colormap(cols);
title(['The colormap used above: m\_colmap(''' nme ''',256,16)']);
if nargout==0
clear cols
end
return;
case 'ste' % step
m=256;
if nargin<3
ncol=16;
end
otherwise
error(['map: ' mfilename ':invalidOption'],...
' Second argument must be an valid option');
end
end
end
% Whatever length colormap we have
if ncol<m/2
xx=[0:(m-1)]'/(m-1)*pi*ncol;
yy=cumsum(cos(xx).^4 + 1/30);
yy=yy-yy(1);
yy=yy/max(yy)*255;
else
yy=[0:(m-1)]'/(m-1)*255;
end
if nargout>0
[r,basecols]=mycols(nme);
cols=interp1(r,basecols,yy);
end
end
function [r,Data]=mycols(nme)
%
% Returns raw colourmap - 0<=r<=255 and
% [0 0 0]<=Data(row,:)<=[1 1 1]
%
r=[0:255]; % Default for most of these.
switch nme
case 'jet'
Data=[...
0.0000000000000000e+00 0.0000000000000000e+00 8.2097987032366326e-01
0.0000000000000000e+00 0.0000000000000000e+00 8.2810185708388151e-01
0.0000000000000000e+00 1.6244801768825715e-02 8.3523804428475601e-01
0.0000000000000000e+00 3.3036471648334995e-02 8.4238547984011569e-01
0.0000000000000000e+00 4.9815313296183217e-02 8.4954008831091266e-01
0.0000000000000000e+00 6.4029974334975218e-02 8.5670244416752706e-01
0.0000000000000000e+00 7.6535959975665882e-02 8.6388438002720569e-01
0.0000000000000000e+00 8.8013865699010582e-02 8.7105469052628581e-01
0.0000000000000000e+00 9.8600980176800038e-02 8.7821143148088110e-01
0.0000000000000000e+00 1.0855337679557225e-01 8.8532422388838095e-01
0.0000000000000000e+00 1.1812539206874099e-01 8.9236038456129052e-01
0.0000000000000000e+00 1.2726308783402634e-01 8.9926170553603024e-01
0.0000000000000000e+00 1.3619917896297423e-01 9.0595230153199524e-01
0.0000000000000000e+00 1.4506118969622983e-01 9.1232172813169876e-01
0.0000000000000000e+00 1.5377890552725290e-01 9.1823409334055117e-01
0.0000000000000000e+00 1.6261365170233669e-01 9.2351427566801991e-01
0.0000000000000000e+00 1.7154074948381501e-01 9.2794646225220667e-01
0.0000000000000000e+00 1.8070256379609848e-01 9.3131899478139557e-01
0.0000000000000000e+00 1.9017887289112076e-01 9.3338241072484596e-01
0.0000000000000000e+00 1.9997783192436316e-01 9.3392154621153756e-01
0.0000000000000000e+00 2.1019119971968461e-01 9.3274045531274641e-01
0.0000000000000000e+00 2.2078830806041727e-01 9.2970178242713375e-01
0.0000000000000000e+00 2.3170788397910427e-01 9.2472675872455312e-01
0.0000000000000000e+00 2.4291058720581157e-01 9.1783217933659011e-01
0.0000000000000000e+00 2.5439689340691901e-01 9.0907966847559551e-01
0.0000000000000000e+00 2.6601511242910086e-01 8.9863138701299472e-01
0.0000000000000000e+00 2.7770789341482360e-01 8.8668327712843464e-01
0.0000000000000000e+00 2.8940651531291417e-01 8.7345282146153225e-01
0.0000000000000000e+00 3.0102041216268027e-01 8.5918692717013723e-01
0.0000000000000000e+00 3.1252327536427388e-01 8.4411199405573478e-01
0.0000000000000000e+00 3.2386802405602533e-01 8.2843647500968565e-01
0.0000000000000000e+00 3.3502534309709658e-01 8.1233252376445897e-01
0.0000000000000000e+00 3.4591820537992940e-01 7.9594701247201749e-01
0.0000000000000000e+00 3.5661427072219648e-01 7.7939361987056155e-01
0.0000000000000000e+00 3.6703710422430275e-01 7.6275539017719729e-01
0.0000000000000000e+00 3.7721017332291257e-01 7.4610487594974018e-01
0.0000000000000000e+00 3.8709592071744631e-01 7.2949277318103267e-01
0.0000000000000000e+00 3.9670474982054660e-01 7.1295673554612449e-01
0.0000000000000000e+00 4.0602438327051393e-01 6.9655675508496329e-01
0.0000000000000000e+00 4.1500561550145126e-01 6.8030864681305458e-01
0.0000000000000000e+00 4.2366289307317656e-01 6.6426240828904592e-01
0.0000000000000000e+00 4.3200712706984007e-01 6.4842386975272537e-01
3.0566524560783279e-03 4.3999127354957085e-01 6.3282182663250508e-01