Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/suptitle.m

raw
1 function hout=suptitle(str)
2 %SUPTITLE Puts a title above all subplots.
3 % SUPTITLE('text') adds text to the top of the figure
4 % above all subplots (a "super title"). Use this function
5 % after all subplot commands.
6
7 % Drea Thomas 6/15/95 [email protected]
8 %
9 % Copyright (C) 1997-2012 Drea Thomas
10 %
11 % This free software: you can redistribute it and/or modify
12 % it under the terms of the GNU General Public License as published by
13 % the Free Software Foundation, either version 3 of the License, or
14 % (at your option) any later version.
15 %
16 % It is distributed in the hope that it will be useful,
17 % but WITHOUT ANY WARRANTY; without even the implied warranty of
18 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 % GNU General Public License for more details.
20 %
21 % If you did not received a copy of the GNU General Public License
22 % with this software, see <http://www.gnu.org/licenses/>.
23 %
24
25
26 % Warning: If the figure or axis units are non-default, this
27 % will break.
28
29 % Parameters used to position the supertitle.
30
31 % Amount of the figure window devoted to subplots
32 plotregion = .92;
33
34 % Y position of title in normalized coordinates
35 titleypos = .95;
36
37 % Fontsize for supertitle
38 fs = get(gcf,'defaultaxesfontsize')+4;
39
40 % Fudge factor to adjust y spacing between subplots
41 fudge=1;
42
43 haold = gca;
44 figunits = get(gcf,'units');
45
46 % Get the (approximate) difference between full height (plot + title
47 % + xlabel) and bounding rectangle.
48
49 if (~strcmp(figunits,'pixels')),
50 set(gcf,'units','pixels');
51 pos = get(gcf,'position');
52 set(gcf,'units',figunits);
53 else,
54 pos = get(gcf,'position');
55 end
56 ff = (fs-4)*1.27*5/pos(4)*fudge;
57
58 % The 5 here reflects about 3 characters of height below
59 % an axis and 2 above. 1.27 is pixels per point.
60
61 % Determine the bounding rectange for all the plots
62
63 % h = findobj('Type','axes');
64
65 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
66 % the next line and uncomment the following block.
67
68 h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
69
70 % If you don't have 4.2, use this code instead
71 %ch = get(gcf,'children');
72 %h=[];
73 %for i=1:length(ch),
74 % if strcmp(get(ch(i),'type'),'axes'),
75 % h=[h,ch(i)];
76 % end
77 %end
78
79
80
81
82 max_y=0;
83 min_y=1;
84
85 oldtitle =0;
86 for i=1:length(h),
87 if (~strcmp(get(h(i),'Tag'),'suptitle')),
88 pos=get(h(i),'pos');
89 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
90 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
91 else,
92 oldtitle = h(i);
93 end
94 end
95
96 if max_y > plotregion,
97 scale = (plotregion-min_y)/(max_y-min_y);
98 for i=1:length(h),
99 pos = get(h(i),'position');
100 pos(2) = (pos(2)-min_y)*scale+min_y;
101 pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
102 set(h(i),'position',pos);
103 end
104 end
105
106 np = get(gcf,'nextplot');
107 set(gcf,'nextplot','add');
108 if (oldtitle),
109 delete(oldtitle);
110 end
111 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
112 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
113 set(gcf,'nextplot',np);
114 axes(haold);
115 if nargout,
116 hout=ht;
117 end
118
119
120