wolffd@0
|
1 function hout=suptitle(str, fs)
|
wolffd@0
|
2 %SUPTITLE Puts a title above all subplots.
|
wolffd@0
|
3 % SUPTITLE('text') adds text to the top of the figure
|
wolffd@0
|
4 % above all subplots (a "super title"). Use this function
|
wolffd@0
|
5 % after all subplot commands.
|
wolffd@0
|
6
|
wolffd@0
|
7 % Drea Thomas 6/15/95 drea@mathworks.com
|
wolffd@0
|
8
|
wolffd@0
|
9 % Warning: If the figure or axis units are non-default, this
|
wolffd@0
|
10 % will break.
|
wolffd@0
|
11
|
wolffd@0
|
12 % Parameters used to position the supertitle.
|
wolffd@0
|
13
|
wolffd@0
|
14 % Amount of the figure window devoted to subplots
|
wolffd@0
|
15 plotregion = .92;
|
wolffd@0
|
16
|
wolffd@0
|
17 % Y position of title in normalized coordinates
|
wolffd@0
|
18 titleypos = .95;
|
wolffd@0
|
19
|
wolffd@0
|
20 % Fontsize for supertitle
|
wolffd@0
|
21 if nargin < 2
|
wolffd@0
|
22 fs = get(gcf,'defaultaxesfontsize')+4;
|
wolffd@0
|
23 end
|
wolffd@0
|
24
|
wolffd@0
|
25 % Fudge factor to adjust y spacing between subplots
|
wolffd@0
|
26 fudge=1;
|
wolffd@0
|
27
|
wolffd@0
|
28 haold = gca;
|
wolffd@0
|
29 figunits = get(gcf,'units');
|
wolffd@0
|
30
|
wolffd@0
|
31 % Get the (approximate) difference between full height (plot + title
|
wolffd@0
|
32 % + xlabel) and bounding rectangle.
|
wolffd@0
|
33
|
wolffd@0
|
34 if (~strcmp(figunits,'pixels')),
|
wolffd@0
|
35 set(gcf,'units','pixels');
|
wolffd@0
|
36 pos = get(gcf,'position');
|
wolffd@0
|
37 set(gcf,'units',figunits);
|
wolffd@0
|
38 else,
|
wolffd@0
|
39 pos = get(gcf,'position');
|
wolffd@0
|
40 end
|
wolffd@0
|
41 ff = (fs-4)*1.27*5/pos(4)*fudge;
|
wolffd@0
|
42
|
wolffd@0
|
43 % The 5 here reflects about 3 characters of height below
|
wolffd@0
|
44 % an axis and 2 above. 1.27 is pixels per point.
|
wolffd@0
|
45
|
wolffd@0
|
46 % Determine the bounding rectange for all the plots
|
wolffd@0
|
47
|
wolffd@0
|
48 % h = findobj('Type','axes');
|
wolffd@0
|
49
|
wolffd@0
|
50 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
|
wolffd@0
|
51 % the next line and uncomment the following block.
|
wolffd@0
|
52
|
wolffd@0
|
53 h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
|
wolffd@0
|
54
|
wolffd@0
|
55 % If you don't have 4.2, use this code instead
|
wolffd@0
|
56 %ch = get(gcf,'children');
|
wolffd@0
|
57 %h=[];
|
wolffd@0
|
58 %for i=1:length(ch),
|
wolffd@0
|
59 % if strcmp(get(ch(i),'type'),'axes'),
|
wolffd@0
|
60 % h=[h,ch(i)];
|
wolffd@0
|
61 % end
|
wolffd@0
|
62 %end
|
wolffd@0
|
63
|
wolffd@0
|
64
|
wolffd@0
|
65
|
wolffd@0
|
66
|
wolffd@0
|
67 max_y=0;
|
wolffd@0
|
68 min_y=1;
|
wolffd@0
|
69
|
wolffd@0
|
70 oldtitle =0;
|
wolffd@0
|
71 for i=1:length(h),
|
wolffd@0
|
72 if (~strcmp(get(h(i),'Tag'),'suptitle')),
|
wolffd@0
|
73 pos=get(h(i),'pos');
|
wolffd@0
|
74 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
|
wolffd@0
|
75 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
|
wolffd@0
|
76 else,
|
wolffd@0
|
77 oldtitle = h(i);
|
wolffd@0
|
78 end
|
wolffd@0
|
79 end
|
wolffd@0
|
80
|
wolffd@0
|
81 if max_y > plotregion,
|
wolffd@0
|
82 scale = (plotregion-min_y)/(max_y-min_y);
|
wolffd@0
|
83 for i=1:length(h),
|
wolffd@0
|
84 pos = get(h(i),'position');
|
wolffd@0
|
85 pos(2) = (pos(2)-min_y)*scale+min_y;
|
wolffd@0
|
86 pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
|
wolffd@0
|
87 set(h(i),'position',pos);
|
wolffd@0
|
88 end
|
wolffd@0
|
89 end
|
wolffd@0
|
90
|
wolffd@0
|
91 np = get(gcf,'nextplot');
|
wolffd@0
|
92 set(gcf,'nextplot','add');
|
wolffd@0
|
93 if (oldtitle),
|
wolffd@0
|
94 delete(oldtitle);
|
wolffd@0
|
95 end
|
wolffd@0
|
96 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
|
wolffd@0
|
97 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
|
wolffd@0
|
98 set(gcf,'nextplot',np);
|
wolffd@0
|
99 axes(haold);
|
wolffd@0
|
100 if nargout,
|
wolffd@0
|
101 hout=ht;
|
wolffd@0
|
102 end
|
wolffd@0
|
103
|
wolffd@0
|
104
|
wolffd@0
|
105
|