Doesn’t seem like there’s an official solution to this issue. The current solution was submitted by Per Magne Knutsen, found here. I’ve modified his version to have more control of the subplot shape.
function subplotsqueeze(hFig, W, H)
% Stretch width and height of all subplots in a figure window
% subplotsqueeze(H, W, H) will stretch subplots in figure with handle H by the
% proportional factor W and H for width and height, respectively.
%
% Examples:
% subplotsqueeze(gcf, 1.2, 1.2) will expand all axes by 20%
% subplotsqueeze(gcf, 0.8, 1) will contract all axes' width by 20%
%
% Expansion and contraction is equal in both directions and axes remain
% centered on their current locations.
%
hAx = findobj(hFig, 'type', 'axes');
for h = 1:length(hAx)
vCurrPos = get(hAx(h), 'position'); % current position
set(hAx(h), 'position', (vCurrPos.*[1 1 W H])-[vCurrPos(3)*(W-1)/2 vCurrPos(4)*(H-1)/2 0 0]);
end
return
Leave A Comment