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