


LTPDA_MSUPTITLE Puts a title above all subplots.
MSUPTITLE('text') adds text to the top of the figure
above all subplots (a "super title"). Use this function
after all subplot commands.
M Hewitson - just a copy and rename with some small adjustements
Drea Thomas 6/15/95 drea@mathworks.com
John Cristion 12/13/00 modified
Mark Histed 03/13/04 histed@mit.edu: fix disappearing legend on last plot
Warning: If the figure or axis units are non-default, this
will break.
$Id: ltpda_msuptitle.html,v 1.2 2007/07/10 05:37:14 hewitson Exp $

0001 function hout = ltpda_msuptitle(str) 0002 % LTPDA_MSUPTITLE Puts a title above all subplots. 0003 % MSUPTITLE('text') adds text to the top of the figure 0004 % above all subplots (a "super title"). Use this function 0005 % after all subplot commands. 0006 % 0007 % M Hewitson - just a copy and rename with some small adjustements 0008 % Drea Thomas 6/15/95 drea@mathworks.com 0009 % John Cristion 12/13/00 modified 0010 % Mark Histed 03/13/04 histed@mit.edu: fix disappearing legend on last plot 0011 % 0012 % 0013 % Warning: If the figure or axis units are non-default, this 0014 % will break. 0015 % 0016 % $Id: ltpda_msuptitle.html,v 1.2 2007/07/10 05:37:14 hewitson Exp $ 0017 % 0018 0019 % Parameters used to position the supertitle. 0020 0021 % Amount of the figure window devoted to subplots 0022 plotregion = .92; 0023 0024 % Y position of title in normalized coordinates 0025 titleypos = .95; 0026 0027 % Fontsize for supertitle 0028 %fs = get(gcf,'defaultaxesfontsize')+4; 0029 0030 fs = get(gcf,'defaultaxesfontsize'); 0031 0032 % Fudge factor to adjust y spacing between subplots 0033 fudge=1; 0034 0035 haold = gca; 0036 figunits = get(gcf,'units'); 0037 0038 % Get the (approximate) difference between full height (plot + title 0039 % + xlabel) and bounding rectangle. 0040 0041 if (~strcmp(figunits,'pixels')), 0042 set(gcf,'units','pixels'); 0043 pos = get(gcf,'position'); 0044 set(gcf,'units',figunits); 0045 else 0046 pos = get(gcf,'position'); 0047 end 0048 ff = (fs-4)*1.27*5/pos(4)*fudge; 0049 0050 % The 5 here reflects about 3 characters of height below 0051 % an axis and 2 above. 1.27 is pixels per point. 0052 0053 % Determine the bounding rectange for all the plots 0054 0055 % h = findobj('Type','axes'); 0056 0057 % findobj is a 4.2 thing.. if you don't have 4.2 comment out 0058 % the next line and uncomment the following block. 0059 0060 % h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills 0061 0062 % If you don't have 4.2, use this code instead 0063 ch = get(gcf,'children'); 0064 h=[]; 0065 for i=1:length(ch), 0066 if strcmp(get(ch(i),'type'),'axes'), 0067 h=[h,ch(i)]; 0068 end 0069 end 0070 0071 0072 max_y=0; 0073 min_y=1; 0074 0075 oldtitle =0; 0076 for i=1:length(h), 0077 if (~strcmp(get(h(i),'Tag'),'suptitle')), 0078 pos=get(h(i),'pos'); 0079 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end; 0080 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end; 0081 else 0082 oldtitle = h(i); 0083 end 0084 end 0085 0086 if max_y > plotregion, 0087 scale = (plotregion-min_y)/(max_y-min_y); 0088 for i=1:length(h), 0089 get(h(i),'Tag') 0090 if ~strcmp(get(h(i),'Tag'),'legend') 0091 pos = get(h(i),'position'); 0092 pos(2) = (pos(2)-min_y)*scale+min_y; 0093 pos(4) = pos(4)*scale-(1-scale)*ff/5*3; 0094 set(h(i),'position',pos); 0095 end 0096 end 0097 end 0098 0099 np = get(gcf,'nextplot'); 0100 set(gcf,'nextplot','add'); 0101 if (oldtitle), 0102 delete(oldtitle); 0103 end 0104 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle'); 0105 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs); 0106 set(gcf,'nextplot',np); 0107 axes(haold); 0108 0109 % fix legend if one exists 0110 legH = legend; 0111 if ~isempty(legH) 0112 axes(legH); 0113 end 0114 0115 if nargout, 0116 hout=ht; 0117 end 0118