comparison m-toolbox/classes/+utils/@plottools/msuptitle.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MSUPTITLE Puts a title above all subplots.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MSUPTITLE Puts a title above all subplots.
5 % MSUPTITLE('text') adds text to the top of the figure
6 % above all subplots (a "super title"). Use this function
7 % after all subplot commands.
8 %
9 % CALL: xaxis(x1,x2)
10 %
11 % REMARK: If the figure or axis units are non-default, this will break.
12 %
13 % VERSION: $Id: msuptitle.m,v 1.1 2008/08/05 17:51:32 ingo Exp $
14 %
15 % HISTORY: 15-06-1995 Drea Thomas (drea@mathworks.com)
16 % Creation.
17 % 13-12-2000 John Cristion
18 % Modified.
19 % 13-03-2004 Mark Histed (histed@mit.edu)
20 % Fix disappearing legend on last plot
21 % xx-xx-xxxx M Hewitson
22 % Just a copy and rename with some small adjustements
23 %
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
26 function hout = msuptitle(str)
27
28 % Parameters used to position the supertitle.
29
30 % Amount of the figure window devoted to subplots
31 plotregion = .92;
32
33 % Y position of title in normalized coordinates
34 titleypos = .95;
35
36 % Fontsize for supertitle
37 %fs = get(gcf,'defaultaxesfontsize')+4;
38
39 fs = get(gcf,'defaultaxesfontsize');
40
41 % Fudge factor to adjust y spacing between subplots
42 fudge=1;
43
44 haold = gca;
45 figunits = get(gcf,'units');
46
47 % Get the (approximate) difference between full height (plot + title
48 % + xlabel) and bounding rectangle.
49
50 if (~strcmp(figunits,'pixels')),
51 set(gcf,'units','pixels');
52 pos = get(gcf,'position');
53 set(gcf,'units',figunits);
54 else
55 pos = get(gcf,'position');
56 end
57 ff = (fs-4)*1.27*5/pos(4)*fudge;
58
59 % The 5 here reflects about 3 characters of height below
60 % an axis and 2 above. 1.27 is pixels per point.
61
62 % Determine the bounding rectange for all the plots
63
64 % h = findobj('Type','axes');
65
66 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
67 % the next line and uncomment the following block.
68
69 % h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
70
71 % If you don't have 4.2, use this code instead
72 ch = get(gcf,'children');
73 h=[];
74 for i=1:length(ch),
75 if strcmp(get(ch(i),'type'),'axes'),
76 h=[h,ch(i)];
77 end
78 end
79
80
81 max_y=0;
82 min_y=1;
83
84 oldtitle =0;
85 for i=1:length(h),
86 if (~strcmp(get(h(i),'Tag'),'suptitle')),
87 pos=get(h(i),'pos');
88 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
89 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
90 else
91 oldtitle = h(i);
92 end
93 end
94
95 if max_y > plotregion,
96 scale = (plotregion-min_y)/(max_y-min_y);
97 for i=1:length(h),
98 get(h(i),'Tag')
99 if ~strcmp(get(h(i),'Tag'),'legend')
100 pos = get(h(i),'position');
101 pos(2) = (pos(2)-min_y)*scale+min_y;
102 pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
103 set(h(i),'position',pos);
104 end
105 end
106 end
107
108 np = get(gcf,'nextplot');
109 set(gcf,'nextplot','add');
110 if (oldtitle),
111 delete(oldtitle);
112 end
113 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
114 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
115 set(gcf,'nextplot',np);
116 axes(haold);
117
118 % fix legend if one exists
119 legH = legend;
120 if ~isempty(legH)
121 axes(legH);
122 end
123
124 if nargout,
125 hout=ht;
126 end
127
128 end
129