forked from anne-urai/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprettyColorbar.m
42 lines (35 loc) · 1.14 KB
/
prettyColorbar.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
function handles = prettyColorbar(titleStr, thinning)
if ~exist('thinning', 'var'), thinning = 0.5; end
% ==================================================================
% make colorbar look pretty
% ==================================================================
drawnow;
handles = findall(gcf,'Type','colorbar');
for h = 1:length(handles),
handles(h).TickDirection = 'out';
handles(h).Box = 'off';
% handles(h).LineWidth = 0;
lims = roundn(max(abs(handles(h).Limits)), -2);
handles(h).Ticks = [-lims 0 lims];
handles(h).Limits = [-lims lims];
end
drawnow;
% get original axes
hAllAxes = findobj(gcf,'type','axes'); axpos = {};
for h = 1:length(hAllAxes), axpos{h} = hAllAxes(h).Position; end
% make colorbar thinner
for h = 1:length(handles),
cpos = handles(h).Position;
cpos(3) = thinning*cpos(3);
handles(h).Position = cpos;
if exist('titleStr', 'var'),
handles(h).Label.String = titleStr;
% handles(h).Label.Position(1) = handles(h).Label.Position(1) - 0.3;
end
end
drawnow;
% restore axis pos
for h = 1:length(hAllAxes), set(hAllAxes(h), 'Position', axpos{h}); end
drawnow;
% move
end