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