Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding text outside subplots

854 views
Skip to first unread message

Tor Hauge

unread,
May 16, 2007, 9:43:27 AM5/16/07
to
I'd like to create some space in a figure outside the subplots for
placing text, a common legend, etc. Something like the procedure
explained in Matlab help topic "Placing Text Outside the Axes".

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

unread,
May 16, 2007, 10:31:25 AM5/16/07
to
why not use
uicontrol('style','text','string','whatever','position',[...]) to
place your label anywhere in the figure window?

Yair Altman

Tor Hauge

unread,
May 16, 2007, 3:45:08 PM5/16/07
to
My problem is not how to place the label, but creating space in the
figure window for the label or text or whatever.

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

unread,
May 16, 2007, 3:50:17 PM5/16/07
to
try this: set up a uipanel hPanel in the area of the figure where you
want your subplots. Then, in each subplot invocation, simply add
subplot(...,'parent',hPanel).

Yair Altman

Kelly

unread,
May 16, 2007, 3:54:17 PM5/16/07
to

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

Tor Hauge

unread,
May 16, 2007, 4:59:10 PM5/16/07
to
Thanks a lot Yair and Kelly.

Best regards,
Tor

0 new messages