-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrdbu_sym.m
64 lines (44 loc) · 1.59 KB
/
rdbu_sym.m
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
function newmap = rdbu_sym(h)
%rdbu_sym Blue, white, and red color map.
% rdbu_sym(M) returns an M-by-3 matrix containing a blue to white
% to red colormap, with white corresponding to the CAXIS value closest
% to zero.
% If only negative values are present, only the blue end will be used; if
% only positive values are present, only the red end will be used.
%
% This function relies on reds.m and blues_r.m from the ENIGMA Toolbox
% https://github.com/MICA-MNI/ENIGMA.git
m = size(get(gcf,'colormap'),1);
plottype = gca;
plotID = whos('plottype');
if strcmp(plotID.class, 'matlab.graphics.chart.HeatmapChart')
% Find middle
lims = h.ColorLimits;
elseif strcmp(plotID.class, 'matlab.graphics.axis.Axes')
% Find middle
lims = get(gca, 'CLim');
else
% Find middle
lims = get(gca, 'CLim');
end
zero = [1 1 1];
pos = Reds;
neg = Blues_r;
% Find whether both pos and neg values are present, or only one
if (lims(1) < 0) & (lims(2) > 0)
% It has both negative and positive
if abs(lims(1)) - abs(lims(2)) < eps
fullscale = [neg; zero; pos];
elseif abs(lims(1)) / abs(lims(2)) > 1 %more neg
fullscale = [neg; zero; pos( 1: round(size(pos,1) * (abs(lims(2)) / abs(lims(1))) ) ,:)];
elseif abs(lims(1)) / abs(lims(2)) < 1 %more neg
fullscale = [neg( round(size(neg,1) * (1-(abs(lims(1)) / abs(lims(2)))) ) : end ,:); zero; pos];
end
newmap = fullscale;
elseif lims(1) >= 0
% Just positive
newmap = Reds;
else
% Just negative
newmap = Blues_r;
end