Home > atmlab > graphs > suptitle.m

suptitle

PURPOSE ^

SUPTITLE Puts a title above all subplots.

SYNOPSIS ^

function hout=suptitle(str,titleypos,fsize)

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. 

       SUPTITLE('text',ypos) puts the text at the vertical position
       given by YPOS (in relative units of the figure). Default is 0.96.

      SUPTITLE('text',ypos,fsize) sets the fontsize to FSIZE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

suptitle.m

SOURCE CODE ^

0001 function hout=suptitle(str,titleypos,fsize)
0002 %SUPTITLE Puts a title above all subplots.
0003 %    SUPTITLE('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 %       SUPTITLE('text',ypos) puts the text at the vertical position
0008 %       given by YPOS (in relative units of the figure). Default is 0.96.
0009 %
0010 %      SUPTITLE('text',ypos,fsize) sets the fontsize to FSIZE
0011   
0012 % Drea Thomas 6/15/95 drea@mathworks.com
0013 % Changed by Patrick Eriksson 990922
0014 % Added to Atmlab by Patrick Eriksson 071102.
0015 
0016 % Warning: If the figure or axis units are non-default, this
0017 % will break.
0018 
0019 % Parameters used to position the supertitle.
0020 
0021 % Amount of the figure window devoted to subplots
0022 plotregion = .95;         % Now not used PE 990922
0023 
0024 % Y position of title in normalized coordinates
0025 if ~exist('titleypos')    % PE 990922
0026   titleypos  = .96;
0027 end
0028 
0029 % Fontsize for supertitle
0030 if exist('fsize')         % PE 990922
0031   fs = fsize;
0032 else
0033   fs = get(gcf,'defaultaxesfontsize')+4;
0034 end
0035 
0036 % Fudge factor to adjust y spacing between subplots
0037 fudge=1;
0038 
0039 haold = gca;
0040 figunits = get(gcf,'units');
0041 
0042 % Get the (approximate) difference between full height (plot + title
0043 % + xlabel) and bounding rectangle.
0044 
0045     if (~strcmp(figunits,'pixels')),
0046         set(gcf,'units','pixels');
0047         pos = get(gcf,'position');
0048         set(gcf,'units',figunits);
0049     else,
0050         pos = get(gcf,'position');
0051     end
0052     ff = (fs-4)*1.27*5/pos(4)*fudge;
0053 
0054         % The 5 here reflects about 3 characters of height below
0055         % an axis and 2 above. 1.27 is pixels per point.
0056 
0057 % Determine the bounding rectange for all the plots
0058 
0059 % h = findobj('Type','axes');
0060 
0061 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
0062 % the next line and uncomment the following block.
0063     
0064 h = findobj(gcf,'Type','axes');  % Change suggested by Stacy J. Hills
0065 
0066 % If you don't have 4.2, use this code instead
0067 %ch = get(gcf,'children');
0068 %h=[];
0069 %for i=1:length(ch),
0070 %  if strcmp(get(ch(i),'type'),'axes'),
0071 %    h=[h,ch(i)];
0072 %  end
0073 %end
0074 
0075     
0076 
0077 
0078 max_y=0;
0079 min_y=1;
0080 
0081 oldtitle =0;
0082 for i=1:length(h),
0083     if (~strcmp(get(h(i),'Tag'),'suptitle')),
0084         pos=get(h(i),'pos');
0085         if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
0086         if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
0087     else,
0088         oldtitle = h(i);
0089     end
0090 end
0091 
0092 if 0  % Part removed by PE
0093 if max_y > plotregion,
0094     scale = (plotregion-min_y)/(max_y-min_y);
0095     for i=1:length(h),
0096         pos = get(h(i),'position');
0097         pos(2) = (pos(2)-min_y)*scale+min_y;
0098         pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
0099         set(h(i),'position',pos);
0100     end
0101 end
0102 end
0103 
0104 np = get(gcf,'nextplot');
0105 set(gcf,'nextplot','add');
0106 if (oldtitle),
0107     delete(oldtitle);
0108 end
0109 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
0110 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center', ...
0111                    'fontsize',fs, 'fontweight', 'bold');
0112 set(gcf,'nextplot',np);
0113 axes(haold);
0114 if nargout,
0115     hout=ht;
0116 end
0117 
0118 
0119

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005