1 |
function jointfig(hfig,no_row,no_col) |
---|
2 |
|
---|
3 |
% jointfig(hfig,no_row,no_col) |
---|
4 |
% --> joint subplots without any space between them |
---|
5 |
% hfig : figure handler, if none, keyin gcf instead |
---|
6 |
% no_row : No. of row subplots |
---|
7 |
% no_col : No. of column subplots |
---|
8 |
% |
---|
9 |
% DO-SIG GONG, |
---|
10 |
% mail: D.Gong@soton.ac.uk |
---|
11 |
% HFRU/ISVR, University of Southampton, UK |
---|
12 |
% latest modified at 99-03-01 7:27PM |
---|
13 |
% |
---|
14 |
% Calls: none |
---|
15 |
|
---|
16 |
% All the movement of subplots should be done in unit of points |
---|
17 |
figure(hfig), hsubplot = get(hfig,'Children'); |
---|
18 |
% convert the position unit from pixel into points : should be restored) |
---|
19 |
set(hfig,'unit','point') |
---|
20 |
|
---|
21 |
% BEWARE! hsubplot has different order from the original subplot sequence |
---|
22 |
% for instance, |
---|
23 |
% |
---|
24 |
% ----------------------- ----------------------- |
---|
25 |
% | 1 | 2 | | 4 | 3 | |
---|
26 |
% |----------+-----------| |----------+-----------| |
---|
27 |
% | 3 | 4 | | 2 | 1 | |
---|
28 |
% ----------------------- ----------------------- |
---|
29 |
% subplot(22i) get(gcf,'Children') |
---|
30 |
% |
---|
31 |
% THEREFORE, transpose hsubplot into the one in original subplot sequence, like this.. |
---|
32 |
|
---|
33 |
hsubplot = hsubplot(length(hsubplot):-1:1); |
---|
34 |
|
---|
35 |
no_subplot1 = length(hsubplot); |
---|
36 |
no_space = no_row*no_col; |
---|
37 |
no_delta = no_space - no_subplot1; |
---|
38 |
|
---|
39 |
% in case of the odd number of subplots |
---|
40 |
if no_delta, |
---|
41 |
for i = 1:no_delta |
---|
42 |
addsubplot = subplot(no_row,no_col,no_subplot1+i); |
---|
43 |
hsubplot = [hsubplot; addsubplot]; |
---|
44 |
end |
---|
45 |
end |
---|
46 |
|
---|
47 |
no_subplot = length(hsubplot); |
---|
48 |
|
---|
49 |
% Default position of figure in a window in point coord |
---|
50 |
|
---|
51 |
for i=1:no_subplot, |
---|
52 |
set(hsubplot(i),'unit','point'), |
---|
53 |
tmp_ylab_pos = get(get(hsubplot(i),'ylabel'),'position'); |
---|
54 |
ylab_pos(i) = tmp_ylab_pos(1); |
---|
55 |
end |
---|
56 |
|
---|
57 |
new_ylab_pos = min(ylab_pos); |
---|
58 |
|
---|
59 |
coner1 = get(hsubplot(1),'position'); |
---|
60 |
coner2 = get(hsubplot(length(hsubplot)),'position'); |
---|
61 |
|
---|
62 |
% position of lowest-left coner |
---|
63 |
inix = coner1(1); |
---|
64 |
iniy = coner2(2)*1.13; |
---|
65 |
|
---|
66 |
% axis line width |
---|
67 |
alinewidth = get(hsubplot(1),'linewidth'); |
---|
68 |
|
---|
69 |
% total lengths |
---|
70 |
total_xlength = (coner2(1) + coner2(3) - coner1(1)) + (no_col-1) * alinewidth; |
---|
71 |
total_ylength = (coner1(2) + coner1(4) - coner2(2)) + (no_row-1) * alinewidth; |
---|
72 |
|
---|
73 |
% width of each subplot |
---|
74 |
delx = 1.0 * total_xlength / no_col; |
---|
75 |
|
---|
76 |
% height of each subplot |
---|
77 |
dely = 0.97 * total_ylength / no_row; |
---|
78 |
|
---|
79 |
%index_loop = 0; % total subplots index |
---|
80 |
%for index_row = 1:no_row, % loop for row index |
---|
81 |
% for index_col = 1:no_col % loop for column index |
---|
82 |
% index_loop = index_loop+1; |
---|
83 |
% |
---|
84 |
% startx = inix + (index_col - 1) * delx; |
---|
85 |
% starty = iniy + (no_row - index_row) * dely; |
---|
86 |
% |
---|
87 |
%%.......It's kind of bug of MATLAB |
---|
88 |
% if alinewidth < 1.0 |
---|
89 |
% set(hsubplot(index_loop),'position',... |
---|
90 |
% [ startx - 0.5 * alinewidth * (index_col-1), ... |
---|
91 |
% starty - 0.5 * alinewidth * (index_row-1), delx ,dely]); |
---|
92 |
%% [startx-1.0*alinewidth*(index_col-1), starty+1.5*alinewidth*(index_row-1), delx ,dely]); |
---|
93 |
% else |
---|
94 |
% set(hsubplot(index_loop),'position',[startx, starty, delx ,dely]); |
---|
95 |
% end |
---|
96 |
% |
---|
97 |
% subplot(hsubplot(index_loop)); |
---|
98 |
|
---|
99 |
index_loop = no_subplot+1; % total subplots index (reverse order) |
---|
100 |
for index_row = no_row:-1:1, % loop for row index |
---|
101 |
for index_col = no_col:-1:1 % loop for column index |
---|
102 |
index_loop = index_loop - 1; |
---|
103 |
|
---|
104 |
startx = inix + (index_col - 1) * delx; |
---|
105 |
starty = iniy + (no_row - index_row) * dely; |
---|
106 |
POSITION = [startx, starty, delx ,dely]; |
---|
107 |
|
---|
108 |
%.......It's kind of bug of MATLAB |
---|
109 |
if alinewidth < 1.0 |
---|
110 |
POSITION = [ startx - 0.5 * alinewidth * (index_col-1), ... |
---|
111 |
starty + 0.9 * alinewidth * (index_row-1), delx ,dely]; |
---|
112 |
% POSITION = [startx-1.0*alinewidth*(index_col-1), starty+1.5*alinewidth*(index_row-1), delx ,dely]); |
---|
113 |
end |
---|
114 |
|
---|
115 |
set(hsubplot(index_loop),'position',POSITION); |
---|
116 |
|
---|
117 |
subplot(hsubplot(index_loop)); |
---|
118 |
|
---|
119 |
iscale = size(get(gca,'yscale'),2); % 3:log, 6:linear |
---|
120 |
|
---|
121 |
% remove xlabels & xticklabels of subplots located in upper rows other than lowest row |
---|
122 |
|
---|
123 |
if index_row ~= no_row, |
---|
124 |
if ~(no_delta & index_row == (no_row - 1) & index_col == no_col), |
---|
125 |
set(get(gca,'xlabel'),'String',[]) |
---|
126 |
set(gca,'xticklabel',[]); %remove xticklabel |
---|
127 |
end |
---|
128 |
end |
---|
129 |
|
---|
130 |
% remove ylabels & yticklabels of subplots located in right columns other than leftmost column |
---|
131 |
if index_col ~= 1, |
---|
132 |
set(get(gca,'ylabel'),'String',[]) |
---|
133 |
set(gca,'yticklabel',[]); %remove yticklabel |
---|
134 |
end |
---|
135 |
|
---|
136 |
% remove first yticklabel of subplots located in lower rows other than highest row, linear yscale only |
---|
137 |
% .... only linear scale |
---|
138 |
if index_row ~= 1 & iscale == 6 |
---|
139 |
a = get(gca,'ytick'); b = get(gca,'ylim'); |
---|
140 |
if a(length(a)) == b(length(b)), |
---|
141 |
a = a(1:length(a)-1); |
---|
142 |
set(gca,'ytick',a); |
---|
143 |
end |
---|
144 |
end |
---|
145 |
|
---|
146 |
% remove first xticklabel of subplots located in left columns other than rightmost column |
---|
147 |
% .... only linear scale |
---|
148 |
|
---|
149 |
if ~no_delta, |
---|
150 |
if index_col ~= no_col & iscale == 6 |
---|
151 |
a = get(gca,'xtick'); b = get(gca,'xlim'); |
---|
152 |
if a(length(a)) == b(length(b)), |
---|
153 |
a = a(1:length(a)-1); |
---|
154 |
set(gca,'xtick',a); |
---|
155 |
end |
---|
156 |
end |
---|
157 |
else |
---|
158 |
if index_col == no_col & index_row == no_row - 1 & iscale == 6, |
---|
159 |
a = get(gca,'xtick'); |
---|
160 |
a = a(2:length(a)); |
---|
161 |
set(gca,'xtick',a); |
---|
162 |
end |
---|
163 |
end |
---|
164 |
|
---|
165 |
end |
---|
166 |
end |
---|
167 |
|
---|
168 |
% get back to initial unit |
---|
169 |
set(hfig,'unit','default') |
---|
170 |
for i=1:no_subplot, set(hsubplot(i),'unit','default'),end |
---|
171 |
|
---|
172 |
% delete dummy subplots |
---|
173 |
if no_delta, for i = 1:no_delta, delete(hsubplot(no_subplot1+i)); end, end |
---|