Warning, /verification/tutorial_global_oce_latlon/diags_matlab/suptitle.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
051ee7f715 Jean*0001 function hout=suptitle(str)
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 % Drea Thomas 6/15/95 drea@mathworks.com
0008 %
0009 % Warning: If the figure or axis units are non-default, this
0010 % will break.
0011
0012 % Parameters used to position the supertitle.
0013
0014 % Amount of the figure window devoted to subplots
0015 plotregion = .92;
0016
0017 % Y position of title in normalized coordinates
0018 titleypos = .95;
0019
0020 % Fontsize for supertitle
0021 fs = get(gcf,'defaultaxesfontsize')+4;
0022
0023 % Fudge factor to adjust y spacing between subplots
0024 fudge=1;
0025
0026 haold = gca;
0027 figunits = get(gcf,'units');
0028
0029 % Get the (approximate) difference between full height (plot + title
0030 % + xlabel) and bounding rectangle.
0031
0032 if (~strcmp(figunits,'pixels')),
0033 set(gcf,'units','pixels');
0034 pos = get(gcf,'position');
0035 set(gcf,'units',figunits);
0036 else,
0037 pos = get(gcf,'position');
0038 end
0039 ff = (fs-4)*1.27*5/pos(4)*fudge;
0040
0041 % The 5 here reflects about 3 characters of height below
0042 % an axis and 2 above. 1.27 is pixels per point.
0043
0044 % Determine the bounding rectange for all the plots
0045
0046 % h = findobj('Type','axes');
0047
0048 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
0049 % the next line and uncomment the following block.
0050
0051 h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
0052
0053 % If you don't have 4.2, use this code instead
0054 %ch = get(gcf,'children');
0055 %h=[];
0056 %for i=1:length(ch),
0057 % if strcmp(get(ch(i),'type'),'axes'),
0058 % h=[h,ch(i)];
0059 % end
0060 %end
0061
0062
0063
0064
0065 max_y=0;
0066 min_y=1;
0067
0068 oldtitle =0;
0069 for i=1:length(h),
0070 if (~strcmp(get(h(i),'Tag'),'suptitle')),
0071 pos=get(h(i),'pos');
0072 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
0073 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
0074 else,
0075 oldtitle = h(i);
0076 end
0077 end
0078
0079 if max_y > plotregion,
0080 scale = (plotregion-min_y)/(max_y-min_y);
0081 for i=1:length(h),
0082 pos = get(h(i),'position');
0083 pos(2) = (pos(2)-min_y)*scale+min_y;
0084 pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
0085 set(h(i),'position',pos);
0086 end
0087 end
0088
0089 np = get(gcf,'nextplot');
0090 set(gcf,'nextplot','add');
0091 if (oldtitle),
0092 delete(oldtitle);
0093 end
0094 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
0095 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
0096 set(gcf,'nextplot',np);
0097 axes(haold);
0098 if nargout,
0099 hout=ht;
0100 end
0101
0102
0103