-
Notifications
You must be signed in to change notification settings - Fork 0
/
suptitle_cb_auto.m
113 lines (92 loc) · 2.7 KB
/
suptitle_cb_auto.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function hout=suptitle_cb_auto(str)
%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 is a helper function for yeastdemo.
% Copyright 2003-2004 The MathWorks, Inc.
% $Revision: 1.1.6.6 $ $Date: 2009/01/30 14:40:12 $
% Warning: If the figure or axis units are non-default, this
% will break.
% Parameters used to position the supertitle.
% Amount of the figure window devoted to subplots
plotregion = .92;
% Y position of title in normalized coordinates
titleypos = .95;
% Fontsize for supertitle
fs = get(gcf,'defaultaxesfontsize')+4;
% Fudge factor to adjust y spacing between subplots
fudge=1;
haold = gca;
figunits = get(gcf,'units');
% Get the (approximate) difference between full height (plot + title
% + xlabel) and bounding rectangle.
if (~strcmp(figunits,'pixels')),
set(gcf,'units','pixels');
pos = get(gcf,'position');
set(gcf,'units',figunits);
else
pos = get(gcf,'position');
end
ff = (fs-4)*1.27*5/pos(4)*fudge;
% The 5 here reflects about 3 characters of height below
% an axis and 2 above. 1.27 is pixels per point.
% Determine the bounding rectangle for all the plots
% h = findobj('Type','axes');
% findobj is a 4.2 thing.. if you don't have 4.2 comment out
% the next line and uncomment the following block.
h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
max_y=0;
min_y=1;
oldtitle =0;
numAxes = length(h);
thePositions = zeros(numAxes,4);
for i=1:numAxes
pos=get(h(i),'pos');
thePositions(i,:) = pos;
if (~strcmp(get(h(i),'Tag'),'suptitle')),
if (pos(2) < min_y)
min_y=pos(2)-ff/5*3;
end;
if (pos(4)+pos(2) > max_y)
max_y=pos(4)+pos(2)+ff/5*2;
end;
else
oldtitle = h(i);
end
end
if max_y > plotregion,
scale = (plotregion-min_y)/(max_y-min_y);
for i=1:numAxes
tag = get( h(i), 'tag' )
%if (~strcmp(get(h(i),'Tag'),'Colorbar')),
if( ~strcmp( tag, 'Colorbar' ) && ~strcmp( tag, 'legend' ) )
pos = thePositions(i,:);
pos(2) = (pos(2)-min_y)*scale+min_y;
pos(4) = pos(4)*scale-(1-scale)*ff/5*3;
try
set(h(i),'position',pos);
catch me
i
numAxes
tag
me.message
keyboard
end
end
end
end
np = get(gcf,'nextplot');
set(gcf,'nextplot','add');
if (oldtitle),
delete(oldtitle);
end
axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
ht=text(.5,titleypos-1,str);set(ht,'horizontalalignment','center','fontsize',fs);
set(gcf,'nextplot',np);
axes(haold); %#ok<MAXES>
if nargout,
hout=ht;
end