ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
bwr.m
Go to the documentation of this file.
1%> \brief
2%> Return a blue-white-red colormap matrix
3%> of shape ``(nell, 3)`` containing the RGB values with
4%> white corresponding to the CAXIS value closest to zero.<br>
5%>
6%> \note
7%> This colormap is most useful for images and surface plots
8%> with positive and negative values.<br>
9%>
10%> \param[in] nell : The input scalar MATLAB integer representing
11%> the number of elements (rows) of the output colormap matrix.<br>
12%> (**optional**, default = ``size(get(gcf, 'colormap'), 1)``)
13%> \param[in] clim : The input vector length ``2`` of MATLAB doubles
14%> representing the color limits of the output colormap.<br>
15%> (**optional**, default = ``get(gca, 'CLim')``)
16%>
17%> \return
18%> ``cmap`` : The output blue-white-red colormap matrix
19%> of shape ``[nell, 3]`` containing a **cold** colormap.<br>
20%>
21%> \interface{bwr}
22%> \code{.m}
23%>
24%> cmap = pm.vis.cmap.cold()
25%> cmap = pm.vis.cmap.cold([])
26%> cmap = pm.vis.cmap.cold(nell)
27%>
28%> \endcode
29%>
30%> \see
31%> MATLAB intrinsic functions ``hsv()``, ``hot()``, ``cool()``, ``bone()``, ``copper()``, ``pink()``, ``flag()``, ``colormap()``, ``rgbplot()``.<br>
32%>
33%> \example{bwr}
34%> \include{lineno} example/vis/cmap/bwr/main.m
35%> \vis{bwr}
36%> \image html example/vis/cmap/bwr/bwr.1.png width=700
37%> \image html example/vis/cmap/bwr/bwr.2.png width=700
38%> \image html example/vis/cmap/bwr/bwr.3.png width=700
39%> \image html example/vis/cmap/bwr/bwr.4.png width=700
40%>
41%> \final{bwr}
42%>
43%> Copyright (c) 2009, Nathan Childress
44%> All rights reserved.
45%>
46%> Redistribution and use in source and binary forms, with or without
47%> modification, are permitted provided that the following conditions are
48%> met:
49%>
50%> * Redistributions of source code must retain the above copyright
51%> notice, this list of conditions and the following disclaimer.
52%> * Redistributions in binary form must reproduce the above copyright
53%> notice, this list of conditions and the following disclaimer in
54%> the documentation and/or other materials provided with the distribution
55%>
56%> This software is provided by the copyright holders and contributors "as is"
57%> and any express or implied warranties, including, but not limited to, the
58%> implied warranties of merchantability and fitness for a particular purpose
59%> are disclaimed. in no event shall the copyright owner or contributors be
60%> liable for any direct, indirect, incidental, special, exemplary, or
61%> consequential damages (including, but not limited to, procurement of
62%> substitute goods or services; loss of use, data, or profits; or business
63%> interruption) however caused and on any theory of liability, whether in
64%> contract, strict liability, or tort (including negligence or otherwise)
65%> arising in any way out of the use of this software, even if advised of the
66%> possibility of such damage.
67%>
68%> \author
69%> \JoshuaOsborne, May 21 2024, 7:40 AM, University of Texas at Arlington<br>
70%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
71%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
72function newmap = bwr(nell, clim)
73
74 if nargin < 1 || isempty(nell)
75 nell = size(get(gcf,'colormap'), 1);
76 end
77 bottom = [0, 0, 0.5];
78 botmiddle = [0, 0.5, 1];
79 topmiddle = [1, 0, 0];
80 middle = [1, 1, 1];
81 top = [0.5, 0, 0];
82
83 % Find middle.
84
85 try
86 lims = get(gca, 'CLim');
87 catch
88 lims = clim;
89 end
90
91 % Find ratio of negative to positive.
92
93 if (lims(1) < 0) & (lims(2) > 0)
94
95 % It has both negative and positive
96 % Find ratio of negative to positive
97 ratio = abs(lims(1)) / (abs(lims(1)) + lims(2));
98 neglen = round(nell*ratio);
99 poslen = nell - neglen;
100
101 % Just negative
102
103 new = [bottom; botmiddle; middle];
104 len = length(new);
105 oldsteps = linspace(0, 1, len);
106 newsteps = linspace(0, 1, neglen);
107 newmap1 = zeros(neglen, 3);
108
109 for i = 1 : 3
110 % Interpolate over RGB spaces of colormap
111 newmap1(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
112 end
113
114 % Just positive.
115
116 new = [middle; topmiddle; top];
117 len = length(new);
118 oldsteps = linspace(0, 1, len);
119 newsteps = linspace(0, 1, poslen);
120 newmap = zeros(poslen, 3);
121
122 for i = 1 : 3
123 % Interpolate over RGB spaces of colormap
124 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
125 end
126
127 % And put them together.
128
129 newmap = [newmap1; newmap];
130
131 elseif lims(1) >= 0
132
133 % Just positive.
134
135 new = [middle; topmiddle; top];
136 len = length(new);
137 oldsteps = linspace(0, 1, len);
138 newsteps = linspace(0, 1, nell);
139 newmap = zeros(nell, 3);
140
141 for i = 1 : 3
142 % Interpolate over RGB spaces of colormap
143 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
144 end
145
146 else
147
148 % Just negative.
149
150 new = [bottom; botmiddle; middle];
151 len = length(new);
152 oldsteps = linspace(0, 1, len);
153 newsteps = linspace(0, 1, nell);
154 newmap = zeros(nell, 3);
155
156 for i=1:3
157 % Interpolate over RGB spaces of colormap
158 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
159 end
160
161 end
162 %
163 % nell = 64;
164 % new = [bottom; botmiddle; middle; topmiddle; top];
165 % % x = 1:nell;
166 %
167 % oldsteps = linspace(0, 1, 5);
168 % newsteps = linspace(0, 1, nell);
169 % newmap = zeros(nell, 3);
170 %
171 % for i=1:3
172 % % Interpolate over RGB spaces of colormap
173 % newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
174 % end
175 %
176 % % set(gcf, 'colormap', newmap), colorbar
177
178end
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function abs(in path, in style)
Return the Get absolute canonical path of a file or folder.
function bwr(in nell, in clim)
Return a blue-white-red colormap matrix of shape (nell, 3) containing the RGB values with white corre...
function cold(in nell)
Return a black-blue-cyan-white colormap matrix of shape (nell, 3) containing a cold colormap.
function len(in obj)
Return a scalar MATLAB whole-number containing the length of the input scalar or vector object.