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