-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddABCs.m
70 lines (50 loc) · 1.71 KB
/
addABCs.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
%%%%%This package written by robert wilson, freely available at
% https://github.com/d-r-b-o-b/UsefulMatlabFunctions%%
function tb = addABCs(ax, offset, fontsize, abcString)
% tb = addABCs(ax, offset, fontsize, abcString)
%
% Add letters to axes
% Inputs:
% ax - axes handles
% offset - 2x1 vector of x-offset and y-offset of letter relative to
% default location in normalized units (optional default no
% offset)
% fontsize - (optional default 20) size of fonts!
% abcString - (optional, default A through Z) if you want non-standard
% lettering or numbering of axes or lower case
% e.g. abcString = 'abcd';
%
% Output
% tb - vector of handles to textboxes containing ABCs
% Robert Wilson
% 10-Nov-2011
if exist('abcString')~= 1
abcString = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ'];
end
if exist('fontsize') ~= 1
fontsize = 20;
end
if exist('offset')
for i = 1:length(ax)
pos(i,:) = get(ax(i), 'position');
end
ABCpos = [pos(:,1)+offset(1) pos(:,2)+pos(:,4)+offset(2)];
else
for i = 1:length(ax)
pos(i,:) = get(ax(i), 'outerposition');
end
ABCpos = [pos(:,1) pos(:,2)+pos(:,4)];
end
for i = 1:length(ax)
tb(i) = annotation('textbox');
set(tb(i), 'fontsize', fontsize, 'fontweight', 'bold', ...
'margin', 0, 'horizontalAlignment', 'center', ...
'verticalAlignment', 'top', 'lineStyle', 'none')
set(tb(i), 'fontunits', 'normalized')
fs = get(tb(i), 'fontsize');
set(tb(i), 'fontunits', 'points')
set(tb(i), 'string', abcString(i))
rec = [ABCpos(i,1)-fs/2 ABCpos(i,2)-fs fs fs];
set(tb(i), 'position', rec)
end