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

Useful little utility

183 views
Skip to first unread message

John Williams

unread,
Oct 9, 2000, 2:19:30 AM10/9/00
to
Hi folks,

Recently I was generating some "thumbnail" type figures in matlab, using
subplot to put a whole bunch of images into one image. In the past I've
complained about subplot making the spacing between individual axes too
large, so I came up with a simple but neat solution, which I offer
freely to anybody else who might like it. Vectorisation is left as an
exercise for the reader :)


Regards,

John

%%%%%%%%%%
function scale_subplots(factor)
% scale_subplots(factor)
%
% Scales each axes object in the current figure by 'factor'
% Useful for trimming the white space created by
% subplot with a large number of sub axes
%
% Operates on the current figure - easily modifed for
% arbitrary figures
%

% Loop through each axis on a figure, and scale it by factor 'f'

% Get handles to all axes in the figure
H_axes = findobj(gcf,'type','axes');

for i=1:length(H_axes);
H=H_axes(i);
% Get the position and size of the axes
pos = get(H,'position');

x=pos(1);y=pos(2);
w=pos(3);h=pos(4);

% Compute the centre of the axes
cx=x+w/2;
cy=y+h/2;

% scale the width and height
w=w*factor;
h=h*factor;

% Compute the new x and y positions for the scaled axes
x=cx-w/2;
y=cy-h/2;

% And update the axes information to
% effect the change
pos=[x y w h];
set(H,'position',pos);
end

oli...@gmail.com

unread,
Jul 18, 2015, 5:18:15 PM7/18/15
to
Can't believe this was posted 15 years ago...but I found this very helpful! Hope you're still around!
0 new messages