I realize I can do this by setting the position of each subplot, see
the sample code below. But I would like to maintain the automatic
positioning of subplots, and are looking for a way to define a part
(sub square) of the figure where my subplots go, leaving a margin in
the figure for some other use.
Any hints are appreciated.
Tor Hauge
Code example that creates space below subplots for placing a common
legend:
% Create some data
rand('state',127);
T = sort(rand(10,4));
x= (1:rows(T))';
X=[ones(rows(x),1) x];
% Set the positions of subplots
Left1=.1
Left2=Left1+.5
Bottom1=.6
Bottom2=Bottom1-.4
Width=.3
Height=.3
Axes=[Left1 Bottom1 Width Height;...
Left2 Bottom1 Width Height;...
Left1 Bottom2 Width Height;...
Left2 Bottom2 Width Height]
% Generate subplots
for i=1:4
y=T(:,i);
blp=regress(y,X);
subplot('Position',Axes(i,:))
scatter(x,y,'+'); box on; set(gca,...
'XLim',[0 11],'YLim',[0 1.2])
hold on
plot(x,blp(1)+blp(2)*x)
hold off
end
% Create a common legend and place it below the subplots
axes1 = gca;
legend1 = legend(axes1,{'Scatter points',...
'Best Linear Predictor'},...
'Position',...
[0.4 0.05 0.2 0.1],'Orientation','horizontal');
legend('boxoff')
Yair Altman
It would be nice to define an area, say,(.2,.2) to (1,1) in the
figure window for the subplots to go (the outer position for all
subplots), without setting the position of each subplot axes.
Tor Hauge
Yair Altman
Take a look at subaxis in the File Exchange:
<http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3696&objectType=file>
It works similarly to subplot but allows more customization,
including ability to set margins around a groups of axes.
-Kelly
Best regards,
Tor