Debian Codegraph @

packages/rol/example/PDE-OPT/topo-opt/elasticity/bwr.m

raw
1 function newmap = bwr(m)
2 %BLUEWHITERED Blue, white, and red color map.
3 % BLUEWHITERED(M) returns an M-by-3 matrix containing a blue to white
4 % to red colormap, with white corresponding to the CAXIS value closest
5 % to zero. This colormap is most useful for images and surface plots
6 % with positive and negative values. BLUEWHITERED, by itself, is the
7 % same length as the current colormap.
8 %
9 % Examples:
10 % ------------------------------
11 % figure
12 % imagesc(peaks(250));
13 % colormap(bluewhitered(256)), colorbar
14 %
15 % figure
16 % imagesc(peaks(250), [0 8])
17 % colormap(bluewhitered), colorbar
18 %
19 % figure
20 % imagesc(peaks(250), [-6 0])
21 % colormap(bluewhitered), colorbar
22 %
23 % figure
24 % surf(peaks)
25 % colormap(bluewhitered)
26 % axis tight
27 %
28 % See also HSV, HOT, COOL, BONE, COPPER, PINK, FLAG,
29 % COLORMAP, RGBPLOT.
30
31
32 if nargin < 1
33 m = size(get(gcf,'colormap'),1);
34 end
35
36
37 bottom = [0 0 0.3];
38 botmiddle = [0 0.5 1];
39 middle = [1 1 1];
40 topmiddle = [1 0 0];
41 top = [0.3 0 0];
42
43 % Find middle
44 lims = get(gca, 'CLim');
45
46 % Find ratio of negative to positive
47 if (lims(1) < 0) & (lims(2) > 0)
48 % It has both negative and positive
49 % Find ratio of negative to positive
50 ratio = abs(lims(1)) / (abs(lims(1)) + lims(2));
51 neglen = round(m*ratio);
52 poslen = m - neglen;
53
54 % Just negative
55 new = [bottom; botmiddle; middle];
56 len = length(new);
57 oldsteps = linspace(0, 1, len);
58 newsteps = linspace(0, 1, neglen);
59 newmap1 = zeros(neglen, 3);
60
61 for i=1:3
62 % Interpolate over RGB spaces of colormap
63 newmap1(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
64 end
65
66 % Just positive
67 new = [middle; topmiddle; top];
68 len = length(new);
69 oldsteps = linspace(0, 1, len);
70 newsteps = linspace(0, 1, poslen);
71 newmap = zeros(poslen, 3);
72
73 for i=1:3
74 % Interpolate over RGB spaces of colormap
75 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
76 end
77
78 % And put 'em together
79 newmap = [newmap1; newmap];
80
81 elseif lims(1) >= 0
82 % Just positive
83 new = [middle; topmiddle; top];
84 len = length(new);
85 oldsteps = linspace(0, 1, len);
86 newsteps = linspace(0, 1, m);
87 newmap = zeros(m, 3);
88
89 for i=1:3
90 % Interpolate over RGB spaces of colormap
91 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
92 end
93
94 else
95 % Just negative
96 new = [bottom; botmiddle; middle];
97 len = length(new);
98 oldsteps = linspace(0, 1, len);
99 newsteps = linspace(0, 1, m);
100 newmap = zeros(m, 3);
101
102 for i=1:3
103 % Interpolate over RGB spaces of colormap
104 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
105 end
106
107 end