-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathmakecolormap.m
More file actions
73 lines (64 loc) · 1.72 KB
/
Copy pathmakecolormap.m
File metadata and controls
73 lines (64 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function cMap = makecolormap(varargin)
%% MAKECOLORMAP makes smoothly varying colormaps
% a = makeColorMap(beginColor, middleColor, endColor, numSteps);
% a = makeColorMap(beginColor, endColor, numSteps);
% a = makeColorMap(beginColor, middleColor, endColor);
% a = makeColorMap(beginColor, endColor);
%
% all colors are specified as RGB triples
% numSteps is a scalar saying howmany points are in the colormap
%
% Examples:
%
% peaks;
% a = makeColorMap([1 0 0],[1 1 1],[0 0 1],40);
% colormap(a)
% colorbar
%
% peaks;
% a = makeColorMap([1 0 0],[0 0 1],40);
% colormap(a)
% colorbar
%
% peaks;
% a = makeColorMap([1 0 0],[1 1 1],[0 0 1]);
% colormap(a)
% colorbar
%
% peaks;
% a = makeColorMap([1 0 0],[0 0 1]);
% colormap(a)
% colorbar
%
% Reference:
% A. Light & P.J. Bartlein, "The End of the Rainbow? Color Schemes for
% Improved Data Graphics," Eos,Vol. 85, No. 40, 5 October 2004.
% http://geography.uoregon.edu/datagraphics/EOS/Light&Bartlein_EOS2004.pdf
%
defaultNum = 128;
sz = cellfun('prodofsize',varargin);
constraits = vertcat(varargin{sz == 3});
steps = [varargin{sz == 1}];
numcstr = size(constraits,1);
numsteps = numel(steps);
if numsteps < 1
steps = round(diff(linspace(1,defaultNum+1,numcstr)));
elseif numsteps == 1
steps = round(diff(linspace(1,steps+1,numcstr)));
elseif numsteps > numcstr-1
steps = steps(1:numcstr-1);
elseif numcstr-1 ~= numsteps
steps = round(diff(linspace(1,defaultNum+1,numcstr)));
end
steps(1:end-1) = steps(1:end-1)+1;
cMap = [];
for k=1:numcstr-1
cMap = [cMap(1:end-1,:); interpMap(constraits(k,:), constraits(k+1,:), steps(k))];
end
end
function cMap = interpMap(colorStart, colorEnd, n)
cMap = zeros(n,3);
for i = 1:3
cMap(:,i) = linspace(colorStart(i), colorEnd(i), n);
end
end