forked from hs105/Cognitive-Control-Testbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suplabel.m
executable file
·86 lines (81 loc) · 2.64 KB
/
suplabel.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
function [ax,h]=suplabel(text,whichLabel,supAxes)
% PLaces text as a title, xlabel, or ylabel on a group of subplots.
% Returns a handle to the label and a handle to the axis.
% [ax,h]=suplabel(text,whichLabel,supAxes)
% returns handles to both the axis and the label.
% ax=suplabel(text,whichLabel,supAxes)
% returns a handle to the axis only.
% suplabel(text) with one input argument assumes whichLabel='x'
%
% whichLabel is any of 'x', 'y', or 't', specifying whether the
% text is to be the xlable, ylabel, or title respectively.
%
% supAxes is an optional argument specifying the Position of the
% "super" axes surrounding the subplots.
% supAxes defaults to [.075 .075 .85 .85]
% specify supAxes if labels get chopped or overlay subplots
%
% EXAMPLE:
% subplot(2,2,1);ylabel('ylabel1');title('title1')
% subplot(2,2,2);ylabel('ylabel2');title('title2')
% subplot(2,2,3);ylabel('ylabel3');xlabel('xlabel3')
% subplot(2,2,4);ylabel('ylabel4');xlabel('xlabel4')
% [ax,h1]=suplabel('super X label');
% [ax,h2]=suplabel('super Y label','y');
% [ax,h3]=suplabel('super Title' ,'t');
% set(h3,'FontSize',30)
%
% SEE ALSO: text, title, xlabel, ylabel, zlabel, subplot,
% suptitle (Matlab Central)
% Author: Ben Barrowes <barrowes@alum.mit.edu>
if nargin < 3
supAxes=[.08 .08 .84 .84];
ah=findall(gcf,'type','axes');
if ~isempty(ah)
supAxes=[inf,inf,0,0];
leftMin=inf; bottomMin=inf; leftMax=0; bottomMax=0;
axBuf=.04;
set(ah,'units','normalized')
ah=findall(gcf,'type','axes');
for ii=1:length(ah)
if strcmp(get(ah(ii),'Visible'),'on')
thisPos=get(ah(ii),'Position');
leftMin=min(leftMin,thisPos(1));
bottomMin=min(bottomMin,thisPos(2));
leftMax=max(leftMax,thisPos(1)+thisPos(3));
bottomMax=max(bottomMax,thisPos(2)+thisPos(4));
end
end
supAxes=[leftMin-axBuf,bottomMin-axBuf,leftMax-leftMin+axBuf*2,bottomMax-bottomMin+axBuf*2];
end
end
if nargin < 2, whichLabel = 'x'; end
if nargin < 1, help(mfilename); return; end
if ~isstr(text) | ~isstr(whichLabel)
error('text and whichLabel must be strings')
end
whichLabel=lower(whichLabel);
ax=axes('Units','Normal','Position',supAxes,'Visible','off');
if strcmp('t',whichLabel)
set(get(ax,'Title'),'Visible','on')
title(text);
elseif strcmp('x',whichLabel)
set(get(ax,'XLabel'),'Visible','on')
xlabel(text);
elseif strcmp('y',whichLabel)
set(get(ax,'YLabel'),'Visible','on')
ylabel(text);
end
if (nargout < 2)
return
end
if strcmp('t',whichLabel)
h=get(ax,'Title');
set(h,'VerticalAlignment','middle')
elseif strcmp('x',whichLabel)
h=get(ax,'XLabel');
elseif strcmp('y',whichLabel)
h=get(ax,'YLabel');
end
%%%ah=findall(gcf,'type','axes');
%%%'sssssssss',kb