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>
7%> This colormap is most useful
for images and surface plots
8%> with positive and negative values.<br>
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')``)
18%> ``cmap`` : The output blue-white-red colormap matrix
19%> of shape ``[nell, 3]`` containing a **
cold** colormap.<br>
24%> cmap = pm.vis.cmap.cold()
25%> cmap = pm.vis.cmap.cold([])
26%> cmap = pm.vis.cmap.cold(nell)
31%> MATLAB intrinsic functions ``hsv()``, ``hot()``, ``cool()``, ``bone()``, ``copper()``, ``pink()``, ``flag()``, ``colormap()``, ``rgbplot()``.<br>
34%> \include{lineno} example/vis/cmap/
bwr/main.m
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
43%> Copyright (c) 2009, Nathan Childress
44%> All rights reserved.
46%> Redistribution and use in source and binary forms, with or without
47%> modification, are permitted provided that the following conditions are
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
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.
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)
74 if nargin < 1 || isempty(nell)
75 nell = size(get(gcf,
'colormap'), 1);
78 botmiddle = [0, 0.5, 1];
79 topmiddle = [1, 0, 0];
86 lims = get(gca,
'CLim');
91 % Find ratio of negative to positive.
93 if (lims(1) < 0) & (lims(2) > 0)
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;
103 new = [bottom; botmiddle; middle];
105 oldsteps = linspace(0, 1,
len);
106 newsteps = linspace(0, 1, neglen);
107 newmap1 = zeros(neglen, 3);
110 % Interpolate over RGB spaces of colormap
111 newmap1(:,i) = min(max(interp1(oldsteps,
new(:,i), newsteps)
', 0), 1);
116 new = [middle; topmiddle; top];
118 oldsteps = linspace(0, 1, len);
119 newsteps = linspace(0, 1, poslen);
120 newmap = zeros(poslen, 3);
123 % Interpolate over RGB spaces of colormap
124 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
127 % And put them together.
129 newmap = [newmap1; newmap];
135 new = [middle; topmiddle; top];
137 oldsteps = linspace(0, 1,
len);
138 newsteps = linspace(0, 1, nell);
139 newmap = zeros(nell, 3);
142 % Interpolate over RGB spaces of colormap
143 newmap(:,i) = min(max(interp1(oldsteps,
new(:,i), newsteps)
', 0), 1);
150 new = [bottom; botmiddle; middle];
152 oldsteps = linspace(0, 1, len);
153 newsteps = linspace(0, 1, nell);
154 newmap = zeros(nell, 3);
157 % Interpolate over RGB spaces of colormap
158 newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps)', 0), 1);
164 %
new = [bottom; botmiddle; middle; topmiddle; top];
167 % oldsteps = linspace(0, 1, 5);
168 % newsteps = linspace(0, 1, nell);
169 % newmap = zeros(nell, 3);
172 % % Interpolate over RGB spaces of colormap
173 % newmap(:,i) = min(max(interp1(oldsteps,
new(:,i), newsteps)
', 0), 1);
176 % % set(gcf, 'colormap
', newmap), colorbar
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.