|
a |
|
b/util/mtit.m |
|
|
1 |
%MTIT creates a major title in a figure with many axes |
|
|
2 |
% |
|
|
3 |
% MTIT |
|
|
4 |
% - creates a major title above all |
|
|
5 |
% axes in a figure |
|
|
6 |
% - preserves the stack order of |
|
|
7 |
% the axis handles |
|
|
8 |
% |
|
|
9 |
%SYNTAX |
|
|
10 |
%------------------------------------------------------------------------------- |
|
|
11 |
% P = MTIT(TXT,[OPT1,...,OPTn]) |
|
|
12 |
% P = MTIT(FH,TXT,[OPT1,...,OPTn]) |
|
|
13 |
% |
|
|
14 |
%INPUT |
|
|
15 |
%------------------------------------------------------------------------------- |
|
|
16 |
% FH : a valid figure handle [def: gcf] |
|
|
17 |
% TXT : title string |
|
|
18 |
% |
|
|
19 |
% OPT : argument |
|
|
20 |
% ------------------------------------------- |
|
|
21 |
% xoff : +/- displacement along X axis |
|
|
22 |
% yoff : +/- displacement along Y axis |
|
|
23 |
% zoff : +/- displacement along Z axis |
|
|
24 |
% |
|
|
25 |
% title modifier pair(s) |
|
|
26 |
% ------------------------------------------- |
|
|
27 |
% TPx : TVx |
|
|
28 |
% see: get(text) for possible |
|
|
29 |
% parameters/values |
|
|
30 |
% |
|
|
31 |
%OUTPUT |
|
|
32 |
%------------------------------------------------------------------------------- |
|
|
33 |
% par : parameter structure |
|
|
34 |
% .pos : position of surrounding axis |
|
|
35 |
% .oh : handle of last used axis |
|
|
36 |
% .ah : handle of invisible surrounding axis |
|
|
37 |
% .th : handle of main title |
|
|
38 |
% |
|
|
39 |
%EXAMPLE |
|
|
40 |
%------------------------------------------------------------------------------- |
|
|
41 |
% subplot(2,3,[1 3]); title('PLOT 1'); |
|
|
42 |
% subplot(2,3,4); title('PLOT 2'); |
|
|
43 |
% subplot(2,3,5); title('PLOT 3'); |
|
|
44 |
% axes('units','inches',... |
|
|
45 |
% 'color',[0 1 .5],... |
|
|
46 |
% 'position',[.5 .5 2 2]); title('PLOT 41'); |
|
|
47 |
% axes('units','inches',... |
|
|
48 |
% 'color',[0 .5 1],... |
|
|
49 |
% 'position',[3.5 .5 2 2]); title('PLOT 42'); |
|
|
50 |
% shg; |
|
|
51 |
% p=mtit('the BIG title',... |
|
|
52 |
% 'fontsize',14,'color',[1 0 0],... |
|
|
53 |
% 'xoff',-.1,'yoff',.025); |
|
|
54 |
% % refine title using its handle <p.th> |
|
|
55 |
% set(p.th,'edgecolor',.5*[1 1 1]); |
|
|
56 |
|
|
|
57 |
% created: |
|
|
58 |
% us 24-Feb-2003 / R13 |
|
|
59 |
% modified: |
|
|
60 |
% us 24-Feb-2003 / CSSM |
|
|
61 |
% us 06-Apr-2003 / TMW |
|
|
62 |
% us 13-Nov-2009 17:38:17 |
|
|
63 |
|
|
|
64 |
%------------------------------------------------------------------------------- |
|
|
65 |
function par=mtit(varargin) |
|
|
66 |
|
|
|
67 |
defunit='normalized'; |
|
|
68 |
if nargout |
|
|
69 |
par=[]; |
|
|
70 |
end |
|
|
71 |
|
|
|
72 |
% check input |
|
|
73 |
if nargin < 1 |
|
|
74 |
help(mfilename); |
|
|
75 |
return; |
|
|
76 |
end |
|
|
77 |
if isempty(get(0,'currentfigure')) |
|
|
78 |
disp('MTIT> no figure'); |
|
|
79 |
return; |
|
|
80 |
end |
|
|
81 |
|
|
|
82 |
vl=true(size(varargin)); |
|
|
83 |
if ischar(varargin{1}) |
|
|
84 |
vl(1)=false; |
|
|
85 |
figh=gcf; |
|
|
86 |
txt=varargin{1}; |
|
|
87 |
elseif any(ishandle(varargin{1}(:))) &&... |
|
|
88 |
ischar(varargin{2}) |
|
|
89 |
vl(1:2)=false; |
|
|
90 |
figh=varargin{1}; |
|
|
91 |
txt=varargin{2}; |
|
|
92 |
else |
|
|
93 |
error('MTIT> invalid input'); |
|
|
94 |
end |
|
|
95 |
vin=varargin(vl); |
|
|
96 |
[off,vout]=get_off(vin{:}); |
|
|
97 |
|
|
|
98 |
% find surrounding box |
|
|
99 |
ah=findall(figh,'type','axes'); |
|
|
100 |
if isempty(ah) |
|
|
101 |
disp('MTIT> no axis'); |
|
|
102 |
return; |
|
|
103 |
end |
|
|
104 |
oah=ah(1); |
|
|
105 |
|
|
|
106 |
ou=get(ah,'units'); |
|
|
107 |
set(ah,'units',defunit); |
|
|
108 |
ap=get(ah,'position'); |
|
|
109 |
if iscell(ap) |
|
|
110 |
ap=cell2mat(get(ah,'position')); |
|
|
111 |
end |
|
|
112 |
ap=[ min(ap(:,1)),max(ap(:,1)+ap(:,3)),... |
|
|
113 |
min(ap(:,2)),max(ap(:,2)+ap(:,4))]; |
|
|
114 |
ap=[ ap(1),ap(3),... |
|
|
115 |
ap(2)-ap(1),ap(4)-ap(3)]; |
|
|
116 |
|
|
|
117 |
% create axis... |
|
|
118 |
xh=axes('position',ap); |
|
|
119 |
% ...and title |
|
|
120 |
th=title(txt,vout{:}); |
|
|
121 |
tp=get(th,'position'); |
|
|
122 |
set(th,'position',tp+off); |
|
|
123 |
set(xh,'visible','off','hittest','on'); |
|
|
124 |
set(th,'visible','on'); |
|
|
125 |
|
|
|
126 |
% reset original units |
|
|
127 |
ix=find(~strcmpi(ou,defunit)); |
|
|
128 |
if ~isempty(ix) |
|
|
129 |
for i=ix(:).' |
|
|
130 |
set(ah(i),'units',ou{i}); |
|
|
131 |
end |
|
|
132 |
end |
|
|
133 |
|
|
|
134 |
% ...and axis' order |
|
|
135 |
uistack(xh,'bottom'); |
|
|
136 |
axes(oah); %#ok |
|
|
137 |
|
|
|
138 |
if nargout |
|
|
139 |
par.pos=ap; |
|
|
140 |
par.oh=oah; |
|
|
141 |
par.ah=xh; |
|
|
142 |
par.th=th; |
|
|
143 |
end |
|
|
144 |
end |
|
|
145 |
%------------------------------------------------------------------------------- |
|
|
146 |
function [off,vout]=get_off(varargin) |
|
|
147 |
|
|
|
148 |
% search for pairs <.off>/<value> |
|
|
149 |
|
|
|
150 |
off=zeros(1,3); |
|
|
151 |
io=0; |
|
|
152 |
for mode={'xoff','yoff','zoff'}; |
|
|
153 |
ix=strcmpi(varargin,mode); |
|
|
154 |
if any(ix) |
|
|
155 |
io=io+1; |
|
|
156 |
yx=find(ix); |
|
|
157 |
ix(yx+1)=1; |
|
|
158 |
off(1,io)=varargin{yx(end)+1}; |
|
|
159 |
varargin=varargin(xor(ix,1)); |
|
|
160 |
end |
|
|
161 |
end |
|
|
162 |
vout=varargin; |
|
|
163 |
end |
|
|
164 |
%------------------------------------------------------------------------------- |