-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialise_publication_quality_figure.m
More file actions
334 lines (282 loc) · 11.9 KB
/
initialise_publication_quality_figure.m
File metadata and controls
334 lines (282 loc) · 11.9 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
function subplots=initialise_publication_quality_figure(varargin)
% Function maximizes figure size, sets up the print options
% Default values
params.figure_handle=gcf;
params.left_margin=0.5; % 0.5 inch margin
params.right_margin=4.6; % One column (3.5 inch) wide
params.top_margin=0.0; % 0.5 inch margin
params.bottom_margin=0.5;
params.no_of_panels_wide=2;
params.no_of_panels_high=2;
params.axes_padding_left=0.75; % 0.75 inch left padding for labels
params.axes_padding_right=0.25; % 0.25 inch right padding
params.axes_padding_top=0.25; % 0.25 inch top padding
params.x_to_y_axes_ratio=1.0; % ratio of x to y axes lengths
params.panel_label_font_size=14; % font size label
params.font_name='Helvetica';
params.starting_letter=0;
params.individual_panel_labels='';
params.axes_padding_bottom=0.75;
params.relative_row_heights=[];
params.right_dead_space=0;
params.individual_padding=0;
params.left_pads=[];
params.right_pads=[];
params.left_subplot_adjustments=[];
params.right_subplot_adjustments=[];
params.bottom_subplot_adjustments=[];
params.height_subplot_adjustments=[];
params.panel_label_x_offset=[];
params.panel_label_y_offset=[];
params.individual_panels_wide=0;
params.omit_panels=[];
% Check for overrides
params=parse_pv_pairs(params,varargin);
% Updates
if (length(params.axes_padding_bottom)==1)
params.axes_padding_bottom=params.axes_padding_bottom * ...
ones(params.no_of_panels_high,1);
end
if (isempty(params.relative_row_heights))
params.relative_row_heights=ones(params.no_of_panels_high,1);
end
if (params.individual_panels_wide == 0)
params.individual_panels_wide = params.no_of_panels_wide * ...
ones(1, params.no_of_panels_high);
end
% Error checking
if (length(params.axes_padding_bottom)~=params.no_of_panels_high)
disp('Axes padding problem');
end
% Do some preparatory calculations
for row_counter=1:params.no_of_panels_high
across(row_counter)=params.no_of_panels_wide;
if (params.individual_panels_wide(1)>0)
across(row_counter)=params.individual_panels_wide(row_counter);
end
if (~params.individual_padding)
axes_width_inches(row_counter)= ...
(8.5-(params.left_margin+params.right_margin+ ...
params.right_dead_space)- ...
(params.no_of_panels_wide*(params.axes_padding_left+ ...
params.axes_padding_right)))/ ...
across(row_counter);
else
% Calculate the row indices
if (row_counter==1)
row_indices=1:across;
else
row_indices= ...
sum(params.individual_panels_wide(1:(row_counter-1))) + ...
(1:across(row_counter));
end
% Override if horizontal paddings is individually specified
axes_width_inches(row_counter) = (8.5 - ...
(params.left_margin+params.right_margin) - ...
sum(params.left_pads(row_indices)) - ...
sum(params.right_pads(row_indices))) / ...
across(row_counter);
end
end
base_axes_height_inches=axes_width_inches(1)/params.x_to_y_axes_ratio;
% Figure width and height in inches
figure_width=8.5-(params.left_margin+params.right_margin);
if (length(params.axes_padding_top)==1)
figure_height= params.top_margin + ...
(params.no_of_panels_high * params.axes_padding_top) + ...
sum(params.axes_padding_bottom(1:params.no_of_panels_high)) + ...
((sum(params.relative_row_heights(1:params.no_of_panels_high))) ...
*base_axes_height_inches+ ...
params.bottom_margin);
else
figure_height = params.top_margin + ...
(sum(params.axes_padding_top(1:params.no_of_panels_high))) + ...
sum(params.axes_padding_bottom(1:params.no_of_panels_high)) + ...
((sum(params.relative_row_heights(1:params.no_of_panels_high))) ...
*base_axes_height_inches+ ...
params.bottom_margin);
end
ptm=params.top_margin;
pnph=params.no_of_panels_high;
paxpt=params.axes_padding_top;
papb=params.axes_padding_bottom;
prrh=params.relative_row_heights;
pbm=params.bottom_margin;
if (length(params.left_subplot_adjustments)==0)
lhs_adjustments=zeros( ...
params.no_of_panels_wide*params.no_of_panels_high,1);
else
lhs_adjustments=params.left_subplot_adjustments;
end
if (length(params.right_subplot_adjustments)==0)
rhs_adjustments=zeros( ...
params.no_of_panels_wide*params.no_of_panels_high,1);
else
rhs_adjustments=params.right_subplot_adjustments;
end
if (length(params.bottom_subplot_adjustments)==0)
bot_adjustments=zeros( ...
params.no_of_panels_wide*params.no_of_panels_high,1);
else
bot_adjustments=params.bottom_subplot_adjustments;
end
if (length(params.height_subplot_adjustments)==0)
height_adjustments=zeros( ...
params.no_of_panels_wide*params.no_of_panels_high,1);
else
height_adjustments=params.height_subplot_adjustments;
end
% Clear figure
figure(params.figure_handle);
clf;
set(params.figure_handle,'Units','inches','PaperType','usletter');
set(params.figure_handle,'Position', ...
[params.left_margin 9-figure_height figure_width figure_height]);
% Loop through sub-plots
subplots=[];
subplot_counter=0;
for row_counter=1:params.no_of_panels_high
% Calculate the row indices
if (row_counter==1)
row_indices=1:across;
else
if (params.individual_panels_wide(1)>0)
row_indices= ...
sum(params.individual_panels_wide(1:(row_counter-1))) + ...
(1:across(row_counter));
else
row_indices=(row_counter-1)*params.no_of_panels_wide + ...
(1:params.no_of_panels_wide);
end
end
if (~params.individual_panels_wide(1))
holder=params.no_of_panels_wide;
else
holder=params.individual_panels_wide(row_counter);
end
for column_counter=1:holder
subplot_counter=subplot_counter+1;
% Check for omit panels
if (any(params.omit_panels==subplot_counter))
continue;
end
% Set lhs normalized to figure width
if (~params.individual_padding)
lhs=((column_counter-1)* ...
(params.axes_padding_left+axes_width_inches(row_counter)+ ...
params.axes_padding_right) + ...
params.axes_padding_left)/figure_width;
else
lhs = (((column_counter-1)*axes_width_inches(row_counter) ) + ...
sum(params.left_pads(row_indices(1:column_counter))) + ...
sum(params.right_pads(row_indices(1:column_counter-1)))) / figure_width;
end
if (length(params.axes_padding_top)==1)
bottom=(figure_height - params.top_margin - ...
(row_counter*params.axes_padding_top) -...
(sum(params.relative_row_heights(1:row_counter))* ...
base_axes_height_inches) - ...
bot_adjustments(subplot_counter) - ...
sum(params.axes_padding_bottom(1:row_counter-1)))/ ...
figure_height;
else
bottom=(figure_height - params.top_margin - ...
(sum(params.axes_padding_top(1:row_counter))) -...
(sum(params.relative_row_heights(1:row_counter))* ...
base_axes_height_inches - ...
bot_adjustments(subplot_counter)) - ...
sum(params.axes_padding_bottom(1:row_counter-1)))/ ...
figure_height;
end
subplots(subplot_counter)=subplot('Position', ...
[lhs+(lhs_adjustments(subplot_counter)/figure_width) bottom ...
(axes_width_inches(row_counter)- ...
lhs_adjustments(subplot_counter)- ...
rhs_adjustments(subplot_counter))/figure_width ...
(params.relative_row_heights(row_counter)* ...
base_axes_height_inches + ...
bot_adjustments(subplot_counter) + ...
height_adjustments(subplot_counter))/figure_height]);
% Draw Label
if (params.panel_label_font_size>0)
if (0)
% Create the subplot and set up the coordinates for the label
subplot(subplots(subplot_counter));
x_pos=-params.axes_padding_left;
y_pos=params.axes_padding_top + ...
params.relative_row_heights(row_counter)* ...
base_axes_height_inches;
if (row_counter==1)
y_pos=y_pos+params.top_margin;
end
text(x_pos,y_pos, ...
char(subplot_counter+64+params.starting_letter), ...
'FontSize',params.panel_label_font_size, ...
'FontWeight','bold', ...
'Units','inches', ...
'HorizontalAlignment','left', ...
'VerticalAlignment','top', ...
'FontName',params.font_name ...
);
text('Units','data');
else
% Move to the subplot
h=subplot(subplots(subplot_counter));
set(h,'Units','inches');
pos_vector=get(h,'Position');
lhs=pos_vector(1);
top=pos_vector(2)+pos_vector(4);
% Find the positions for the labels
if (~params.individual_padding)
x_pos=-params.axes_padding_left;
else
x_pos=-params.left_pads( ...
row_indices(column_counter));
end
x_pos=x_pos-lhs_adjustments(subplot_counter);
if (~isempty(params.panel_label_x_offset))
x_pos = x_pos + params.panel_label_x_offset(subplot_counter);
end
if (length(params.axes_padding_top)==1)
y_pos=params.axes_padding_top + ...
params.relative_row_heights(row_counter)* ...
base_axes_height_inches;
else
y_pos=params.axes_padding_top(row_counter) + ...
params.relative_row_heights(row_counter)* ...
base_axes_height_inches;
end
if (row_counter==1)
y_pos=y_pos+params.top_margin;
end
y_pos=y_pos+bot_adjustments(subplot_counter)+ ...
height_adjustments(subplot_counter);
if (~isempty(params.panel_label_y_offset))
y_pos = y_pos + params.panel_label_y_offset(subplot_counter);
end
if (length(params.individual_panel_labels)>0)
text_string=params.individual_panel_labels{ ...
subplot_counter};
else
text_string=sprintf('%c', ...
subplot_counter+64+params.starting_letter);
end
% Slight x offset added to prevent labels being cropped
text(x_pos+0.01,y_pos,text_string, ...
'Units','inches', ...
'FontSize',params.panel_label_font_size, ...
'FontWeight','bold', ...
'Units','inches', ...
'HorizontalAlignment','left', ...
'VerticalAlignment','top', ...
'FontName',params.font_name ...
);
text('Units','data');
end
end
hold on;
drawnow;
end
end
% Restore defaults
set(gcf,'PaperUnits','inches')