strange behavior (bug?) with subplot and setting outerposition
Show older comments
I have a chunk of code similar to this. When I run the last command to reset the outerposition of the bottom figure it erases the figure above it. I can then replot that figure, but it doesn't seem to me as if this is working properly. Any ideas as to why? Using 2011a.
Thanks, Doug
%%setup figure
figure;
set(gcf,'Units','inches');
set(gcf,'Position',[2,2,5.75,8]);
g=magic(51);
%%Plot first Column
h=subplot(4,3,1);
imagesc(g);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.75 0.33 0.25])
h=subplot(4,3,4)
imagesc(g^2);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.5 0.33 0.25])
h=subplot(4,3,7)
imagesc(g^3);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.25 0.33 0.25])
h=subplot(4,3,10)
imagesc(g^4);
set(h,'OuterPosition',[0.00 0.00 0.33 0.25])
Accepted Answer
More Answers (1)
Walter Roberson
on 29 Apr 2011
1 vote
The subplot(4,3,10) is chosing the OuterPosition of
[0.0893810444874275, 0.0877777777777778, 0.263695932497968, 0.191075268817204]
The upper left corner of this is
[0.0893810444874275, 0.278853046594982]
That overlaps with the bottom of the subplot above it, which descends to 0.25 after the repositioning.
If you do not do the set() of the outerposition on the four subplots, and then you set() the third of them to the location you have indicated, you can see it move down and overlap the fourth subplot.
The logical error is in thinking that subplot() of an N x M matrix divides the visible figure into exactly N x M equal areas that together cover the original figure. The reality is that subplot includes margins around the edge of the figure in the calculation, so the placement is not at exact divisions of the whole figure.
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!