From: Rob Phor on
I'd like to create a 1x4 subplot where figures are spaced evenly. To do this I expected to execute a simple script like the following:

clear all
x=-1:0.1:1;
for n=1:4
h(n)=subplot(1,4,n);
plot(x,x.^n)
set(h(n),'units','points','position',[100*n 50 50 50])
end

which makes the four subplots correctly spaced

However, when I, say, double the size of the individual subplot (and double the spacing) by adjusting the corresponding line above to:

set(h(n),'units','points','position',[200*n 100 100 100])

only the third and fourth plots show up. What gives? Can anyone else 1) reproduce this and 2) provide a fix?
From: Walter Roberson on
Rob Phor wrote:
> I'd like to create a 1x4 subplot where figures are spaced evenly. To do
> this I expected to execute a simple script like the following:
>
> clear all
> x=-1:0.1:1;
> for n=1:4 h(n)=subplot(1,4,n); plot(x,x.^n)
> set(h(n),'units','points','position',[100*n 50 50 50])
> end
>
> which makes the four subplots correctly spaced
>
> However, when I, say, double the size of the individual subplot (and
> double the spacing) by adjusting the corresponding line above to:
>
> set(h(n),'units','points','position',[200*n 100 100 100])
>
> only the third and fourth plots show up. What gives? Can anyone else 1)
> reproduce this and 2) provide a fix?


subplot divides the figure area into equal sized pieces whose dimensions
are deduced by examining the first two parameters (rows and columns.)
Then, as is clearly documented in the subplot() documentation, if there
is an existing axis covering any part of the deduced area and which is
not -exactly- the same size and position as the deduced area, it deletes
the existing axis.

Thus if you attempt to move the subplots away from their default spacing
or positions, and you do so before you have created all of the axes,
then you are likely to end up with some of the just-created axes deleted.

To fix, use your for loop to record the subplot axes handles first, end
the loop, and -then- loop adjusting the axes sizes/positions .