-
Notifications
You must be signed in to change notification settings - Fork 3
/
colorbar_ndh.m
97 lines (75 loc) · 2.78 KB
/
colorbar_ndh.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
function colorbar_ndh(axis_label,nowidth_flag,width_frac,height_frac,bottom_top_frac,seperation_frac)
% (C) Nick Holschuh - Penn State University - 2017 ([email protected])
% This plots a colorbar with adjusted width, spacing, and properties.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are as follows:
%
% axis_label - The Total Axis label plotted to the right of the bar
% nowidth_flag - If there should be no width adjustment to the original
% plot [1]
% width_frac - The fraction of the original colorbar width to plot
% height_frac - The fraction of the original height to plot
% bottom_top_frac - Vertical position along the figure for the colorbar to
% plot [0 - Bottom aligned up to 1 - Top aligned];
% seperation_frac - whether or not to separate the colorbar further by a
% fractional amount from the plot
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
flipud_flag = 0;
if exist('nowidth_flag') == 0
nowidth_flag = 1;
end
if exist('width_frac') == 0
width_frac = 1;
end
if exist('height_frac') == 0
height_frac = 1;
end
if exist('bottom_top_frac') == 0
bottom_top_frac = 0;
end
if exist('seperation_frac') == 0
seperation_frac = 0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here we get the initial position of the
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% axes, as well as the position
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% post-addition of colorbar, and the
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% position of the colorbar
pos1 = get(gca,'Position');
ccs = colorbar;
ylh = ylabel(ccs,axis_label);
%set(ylh,'BackgroundColor','black','EdgeColor','white');
ylh_pos = get(ylh,'Position');
ylh_pos(1) = ylh_pos(1)+0.5;
set(ylh,'Position',ylh_pos);
pos2 = get(gca,'Position');
cs = get(gcf,'Children');
for i = 1:length(cs)
if length(cs(i).Type) == 8
if cs(i).Type == 'colorbar';
cpos = get(cs(i),'Position');
c_num = i;
break
end
end
end
cpos_final = cpos;
%%% pos2 - main axis positions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is the correction required to shift
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% everything back to its position
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pre-colorbar addition
if nowidth_flag == 1
sep = cpos(1)-(pos2(1)+pos2(3));
set(gca,'Position',pos1);
cpos_final(1) = pos1(1)+pos1(3)+abs(sep)*seperation_frac;
end
cpos_final(3) = cpos_final(3)*width_frac;
vert_range = cpos_final(4)*(1-height_frac);
cpos_final(4) = cpos_final(4)*height_frac;
cpos_final(2) = cpos(2)+bottom_top_frac*vert_range;
set(cs(c_num),'Position',cpos_final)
if flipud_flag == 1
set(cs(c_num),'YDir','reverse')
end
end