-
Notifications
You must be signed in to change notification settings - Fork 0
/
jisuptitle.m
127 lines (101 loc) · 3 KB
/
jisuptitle.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function hout=jisuptitle(str,size)
% JISUPTITLE Puts a title above all subplots. Does not resize axes (unlike suptitle).
%
% hout=jisuptitle(str,[size])
%
% jisuptitle('text') adds text to the top of the figure
% above all subplots (a "super title").
% Size specifies points added to normal plot fontsize. (default
% is 4.)
%
% JRI 10/99 modified--doesn't scale axes
% takes parameters from globals
% called with no args, uses most recent suptitle string
% caled w/ args, sets globals
%
% returns handle to text if asked
% Drea Thomas 6/15/95 [email protected]
global G %SETS: G.plot.layout.jisuptitlestr, G.plot.layout.jisuptitlesize
if isempty(G),
hasglobal = 0;
else
hasglobal = 1;
end
% Parameters used to position the supertitle.
if hasglobal,
% Amount of the figure window devoted to subplots
plotregion = G.plot.layout.yplotregion;
% Y position of title in normalized coordinates
titleypos = G.plot.layout.suptitleypos;
titlexpos = mean(G.plot.layout.xplotregion);
else
plotregion = [.04 .95];
titleypos = 1;
titlexpos = .5;
end
% Fontsize for supertitle
if nargin < 2,
size = 4;
end
% No arguments, get title string from global (stored by last jisuptitle call)
% if string passed in, set global to it
if hasglobal,
if nargin==0,
str = G.plot.layout.jisuptitlestr;
size = G.plot.layout.jisuptitlesize;
else
G.plot.layout.jisuptitlestr = str;
G.plot.layout.jisuptitlesize = size;
end
end
if isempty(str), return;end
fs = get(gcf,'defaultaxesfontsize')+size;
% Fudge factor to adjust y spacing between subplots
fudge=0; %make no adjustments to axes!
currentaxis=~isempty(findobj(gcf,'type','axes'));
if currentaxis,
haold = gca;
%test if this handle is suptitle, if so, don't worry about deleting, since do so later
if (strcmp(get(haold,'Tag'),'suptitle')),
haold=[];
end
else
haold=[];
end
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.
h = findobj(gcf,'Type','axes'); % Change suggested by Stacy J. Hills
max_y=0;
min_y=1;
oldtitle = findobj(gcf, 'Type', 'axes', 'Tag', 'suptitle');
np = get(gcf,'nextplot');
set(gcf,'nextplot','add');
if (~isempty(oldtitle)),
delete(oldtitle);
end
ha=axes('pos',[0 1 1 1],'visible','off','Tag','suptitle');
%massage string
str = protect_underscore(str);
ht=text(titlexpos,titleypos-1,str);
set(ht,'horizontalalignment','center','fontsize',fs,'verticalalignment','top')
%,...'fontweight','bold');
set(gcf,'nextplot',np);
%% this is a nice idea, but if last axis has a legend, it causes
% it to be hid
%if ~isempty(haold)
% axes(haold);
%end
if nargout,
hout=ht;
end