forked from csdms-contrib/slepian_alpha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddcb.m
165 lines (152 loc) · 4.89 KB
/
addcb.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
function varargout=addcb(pos,caxcon,caxoc,parm,tint,invt)
% [cb,xcb]=addcb(pos,caxcon,caxoc,parm,tint,invt)
%
% Adds an explicit colorbar - suitable for use with multiple or complicated
% color maps, or with directly indexed RGB maps, as in IMAGEFNAN. Remember,
% only the tick LABELS are meaningful; their actual positions are not.
%
% INPUT:
%
% pos 'hor' [default], 'vert' or [lbwh]
% caxcon Caxis limits for the "continental" colormap
% caxoc Caxis limits for the "oceanic" colormap
% The defaults of the above are for a dual colormap
% suitable for global topography; if another colormap is
% specified, min([caxoc caxcon]) and max([caxoc caxcon])
% are used as the axis limits on the colorbar; so just give
% them the same values if you're using only one as with IMAGEFNAN.
% parm 1 Topography colormap [default]
% 2 Gravity colormap composed of two sections
% 3 Another colormap identified by a string, e.g. 'kelicol'
% 4 An actual colormap as a rgb matrix, e.g. gray(21)
% tint Interval between the tickmarks [default: one tenth of the range]
% invt 1 Invert the color bar in question
% 0 Don't [default]
%
% OUTPUT:
%
% cb Colorbar axis handle
% xcb Colorbar xlabel axis handle
%
% CAVEAT:
%
% When in doubt, specify the colorbar by name string
%
% SEE ALSO:
%
% PLOTTOPO, PLOTGRAV, JOINCOLMAP, CAX2DEM, SERGEICOL, DEMMAP, IMAGEFDIR
%
% Last modified by fjsimons-at-alum.mit.edu, 06/21/2016
defval('caxcon',[0 1500]);
defval('caxoc',[-7000 0]);
defval('parm',1)
defval('pos','hor')
defval('invt',0)
ah=gca;
fpos=getpos(ah);
poso=pos;
if isstr(pos)
cb=colorbar(pos);
npos=getpos(ah);
pos=getpos(cb);
delete(cb)
set(ah,'position',npos)
end
cb=axes('position',pos);
miC=min([caxoc caxcon]);
maC=max([caxoc caxcon]);
cbd=linspace(miC,maC,500);
defval('tint',(maC-miC)/10)
wis=2;
if length(parm)==1 && parm==1
% Not quite right if it turns out to be vertical
% New length addition to skip for BW
plottopo(cbd,[],caxcon,caxoc,[0 1],[1 0])
elseif length(parm)==1 && parm==2
% New length addition to skip for BW
plotgrav(cbd,-sign(cbd),0,caxcon,caxoc)
elseif [~isstr(parm) && strcmp(poso,'hor')] || ...
[~isstr(parm) && poso(3)>poso(4)]
% New if for BW color bars called by gray(N)
h=parm; if invt==1; h=flipud(h); end
h=reshape(h,[1 size(h,1) size(h,2)]);
imagefdir([miC 1],[maC 0],h);
elseif [~isstr(parm) && strcmp(poso,'vert')] || ...
[~isstr(parm) && poso(4)>poso(3)]
% New if for BW color bars called by gray(N)
h=parm; if invt==0; h=flipud(h); end
h=reshape(h,[1 size(h,1) size(h,2)]);
for index=1:3
hh(:,:,index)=h(:,:,index)';
end
imagefdir([miC 1],[maC 0],hh);
wis=1;
elseif [isstr(parm) && strcmp(poso,'hor')] || poso(3)>poso(4)
h=eval(parm); if invt==1; h=flipud(h); end
h=reshape(h,[1 size(h,1) size(h,2)]);
imagefdir([miC 1],[maC 0],h);
elseif [isstr(parm) && strcmp(poso,'vert')] || poso(4)>poso(3)
h=eval(parm); if invt==0; h=flipud(h); end
h=reshape(h,[1 size(h,1) size(h,2)]);
for index=1:3
hh(:,:,index)=h(:,:,index)';
end
imagefdir([miC 1],[maC 0],hh);
wis=1;
end
noticks(cb,wis)
longticks(cb)
if [~isstr(parm) && strcmp(poso,'hor')]
% New if for BW
xtcb=get(cb,'XTick');
xlcb=get(cb,'XTicklabel');
set(cb,'XTick',xtcb(1:2:end))
set(cb,'XTicklabel',cellstr(xlcb(1:2:end,:)))
elseif [~isstr(parm) && strcmp(poso,'hor')]
% New if for BW
ytcb=get(cb,'YTick');
ylcb=get(cb,'YTicklabel');
set(cb,'YTick',ytcb(1:2:end))
set(cb,'YTicklabel',cellstr(ylcb(1:2:end,:)))
elseif [length(parm)==1 && parm==1] || [length(parm)==1 && parm==2] || ...
([isstr(parm) && strcmp(poso,'hor')] || poso(3)>poso(4))
% New length addition to skip for BW
xtcb=get(cb,'XTick');
xlcb=get(cb,'XTickLabel');
set(cb,'XTick',xtcb(1:2:end))
set(cb,'XTickLabel',cellstr(xlcb(1:2:end,:)))
elseif [isstr(parm) & strcmp(poso,'vert') || poso(4)>poso(3)]
ytcb=get(cb,'YTick');
ylcb=get(cb,'YTickLabel');
set(cb,'YTick',ytcb(1:2:end))
set(cb,'YTickLabel',cellstr(ylcb(1:2:end,:)))
end
if ~isstr(parm) && length(parm)==1
labn={'Topography (km)' 'Gravity (mGal)'};
xcb=xlabel(labn{parm});
elseif [~isstr(parm) && strcmp(poso,'hor')]
xcb=xlabel('add y-label here');
elseif [~isstr(parm) && strcmp(poso,'vert')]
xcb=ylabel('add x-label here');
elseif [isstr(parm) && strcmp(poso,'vert')] ...
|| [~isstr(poso) && poso(4)>poso(3)]
xcb=ylabel('add y-label here');
elseif [isstr(parm) & strcmp(poso,'hor')] ...
|| [~isstr(poso) && poso(3)>poso(4)]
xcb=xlabel('add x-label here');
else
error('Specify valid options')
end
axes(cb)
axis normal
% Add the tick marks on the color bar
if ~isstr(poso) && poso(3)>poso(4)
poso='hor';
elseif ~isstr(poso) && poso(4)>poso(3)
poso='vert';
end
% Transform the tick marks
cbarticks(cb,[miC maC],tint,poso)
% Output
varns={cb,xcb};
varargout=varns(1:nargout);