annotate toolboxes/FullBNT-1.0.7/KPMtools/suptitle.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function hout=suptitle(str, fs)
Daniel@0 2 %SUPTITLE Puts a title above all subplots.
Daniel@0 3 % SUPTITLE('text') adds text to the top of the figure
Daniel@0 4 % above all subplots (a "super title"). Use this function
Daniel@0 5 % after all subplot commands.
Daniel@0 6
Daniel@0 7 % Drea Thomas 6/15/95 drea@mathworks.com
Daniel@0 8
Daniel@0 9 % Warning: If the figure or axis units are non-default, this
Daniel@0 10 % will break.
Daniel@0 11
Daniel@0 12 % Parameters used to position the supertitle.
Daniel@0 13
Daniel@0 14 % Amount of the figure window devoted to subplots
Daniel@0 15 plotregion = .92;
Daniel@0 16
Daniel@0 17 % Y position of title in normalized coordinates
Daniel@0 18 titleypos = .95;
Daniel@0 19
Daniel@0 20 % Fontsize for supertitle
Daniel@0 21 if nargin < 2
Daniel@0 22 fs = get(gcf,'defaultaxesfontsize')+4;
Daniel@0 23 end
Daniel@0 24
Daniel@0 25 % Fudge factor to adjust y spacing between subplots
Daniel@0 26 fudge=1;
Daniel@0 27
Daniel@0 28 haold = gca;
Daniel@0 29 figunits = get(gcf,'units');
Daniel@0 30
Daniel@0 31 % Get the (approximate) difference between full height (plot + title
Daniel@0 32 % + xlabel) and bounding rectangle.
Daniel@0 33
Daniel@0 34 if (~strcmp(figunits,'pixels')),
Daniel@0 35 set(gcf,'units','pixels');
Daniel@0 36 pos = get(gcf,'position');
Daniel@0 37 set(gcf,'units',figunits);
Daniel@0 38 else,
Daniel@0 39 pos = get(gcf,'position');
Daniel@0 40 end
Daniel@0 41 ff = (fs-4)*1.27*5/pos(4)*fudge;
Daniel@0 42
Daniel@0 43 % The 5 here reflects about 3 characters of height below
Daniel@0 44 % an axis and 2 above. 1.27 is pixels per point.
Daniel@0 45
Daniel@0 46 % Determine the bounding rectange for all the plots
Daniel@0 47
Daniel@0 48 % h = findobj('Type','axes');
Daniel@0 49
Daniel@0 50 % findobj is a 4.2 thing.. if you don't have 4.2 comment out
Daniel@0 51 % the next line and uncomment the following block.
Daniel@0 52
Daniel@0 53 h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
Daniel@0 54
Daniel@0 55 % If you don't have 4.2, use this code instead
Daniel@0 56 %ch = get(gcf,'children');
Daniel@0 57 %h=[];
Daniel@0 58 %for i=1:length(ch),
Daniel@0 59 % if strcmp(get(ch(i),'type'),'axes'),
Daniel@0 60 % h=[h,ch(i)];
Daniel@0 61 % end
Daniel@0 62 %end
Daniel@0 63
Daniel@0 64
Daniel@0 65
Daniel@0 66
Daniel@0 67 max_y=0;
Daniel@0 68 min_y=1;
Daniel@0 69
Daniel@0 70 oldtitle =0;
Daniel@0 71 for i=1:length(h),
Daniel@0 72 if (~strcmp(get(h(i),'Tag'),'suptitle')),
Daniel@0 73 pos=get(h(i),'pos');
Daniel@0 74 if (pos(2) < min_y), min_y=pos(2)-ff/5*3;end;
Daniel@0 75 if (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;end;
Daniel@0 76 else,
Daniel@0 77 oldtitle = h(i);
Daniel@0 78 end
Daniel@0 79 end
Daniel@0 80
Daniel@0 81 if max_y > plotregion,
Daniel@0 82 scale = (plotregion-min_y)/(max_y-min_y);
Daniel@0 83 for i=1:length(h),
Daniel@0 84 pos = get(h(i),'position');
Daniel@0 85 pos(2) = (pos(2)-min_y)*scale+min_y;
Daniel@0 86 pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
Daniel@0 87 set(h(i),'position',pos);
Daniel@0 88 end
Daniel@0 89 end
Daniel@0 90
Daniel@0 91 np = get(gcf,'nextplot');
Daniel@0 92 set(gcf,'nextplot','add');
Daniel@0 93 if (oldtitle),
Daniel@0 94 delete(oldtitle);
Daniel@0 95 end
Daniel@0 96 ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
Daniel@0 97 ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
Daniel@0 98 set(gcf,'nextplot',np);
Daniel@0 99 axes(haold);
Daniel@0 100 if nargout,
Daniel@0 101 hout=ht;
Daniel@0 102 end
Daniel@0 103
Daniel@0 104
Daniel@0 105