suptitle

PURPOSE ^

SUPTITLE Puts a title above all subplots.

SYNOPSIS ^

function hout=suptitle(str)

DESCRIPTION ^

SUPTITLE Puts a title above all subplots.
    SUPTITLE('text') adds text to the top of the figure
    above all subplots (a "super title"). Use this function
    after all subplot commands.

 Original file from Drea Thomas 6/15/95 drea@mathworks.com
 Imported from Matlab Central

 Warning: If the figure or axis units are non-default, this
 will break.

 $Id: suptitle.m,v 1.1 2004/05/12 16:22:59 dalai Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Sun 15-Aug-2004 22:13:10 by m2html © 2003