-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmf_label.m
70 lines (59 loc) · 1.48 KB
/
mf_label.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
%==========================================================================
%
%
% input :
%
% output :
%
% Example:
% mf_label(ax, txt, 'bottomleft', 'BackGroundColor', 'none')
% mf_label(ax, txt, 'topright', 'EdgeColor', 'k')
%
% Siqi Li, SMAST
% yyyy-mm-dd
%
% Updates:
%
%==========================================================================
function h = mf_label(ax, txt, location, varargin)
varargin = read_varargin(varargin, {'kH'}, {0.03});
varargin = read_varargin(varargin, {'kV'}, {0.036});
xlims = get(ax, 'xlim');
ylims = get(ax, 'ylim');
x1 = xlims(1);
x2 = xlims(2);
y1 = ylims(1);
y2 = ylims(2);
dx = x2 - x1;
dy = y2 - y1;
% kH = 0.03;
% kV = 0.036;
if contains(lower(location), 'bottom')
py = y1 + kV*dy;
elseif contains(lower(location), 'top')
py = y2 - kV*dy;
else
error('Wrong location')
end
if contains(lower(location), 'left')
px = x1 + kH*dx;
elseif contains(lower(location), 'right')
px = x2 - kH*dx;
else
error('Wrong location')
end
h = text(ax, px, py, txt);
set(h, 'BackGroundColor', 'w')
if contains(lower(location), 'bottom')
set(h, 'VerticalAlignment', 'bottom')
elseif contains(lower(location), 'top')
set(h, 'VerticalAlignment', 'top')
end
if contains(lower(location), 'left')
set(h, 'HorizontalAlignment', 'left')
elseif contains(lower(location), 'right')
set(h, 'HorizontalAlignment', 'right')
end
if ~isempty(varargin)
set(h, varargin{:})
end