strange behavior (bug?) with subplot and setting outerposition

7 Ansichten (letzte 30 Tage)
Doug
Doug am 29 Apr. 2011
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])

Akzeptierte Antwort

Jarrod Rivituso
Jarrod Rivituso am 29 Apr. 2011
I'm not 100% sure why it is removing the third axes.
That aside, I've got a couple thoughts for ya
1. If you are going to set the OuterPosition manually anyway, you don't need subplot.
%%setup figure
figure;
set(gcf,'Units','inches');
set(gcf,'Position',[2,2,5.75,8]);
g=magic(51);
%%Plot first Column
h=axes;
imagesc(g);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.75 0.33 0.25])
h=axes;
imagesc(g^2);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.5 0.33 0.25])
h=axes;
imagesc(g^3);
set(gca,'xtick',[]);
set(h,'OuterPosition',[0.00 0.25 0.33 0.25])
h=axes;
imagesc(g^4);
set(h,'OuterPosition',[0.00 0.00 0.33 0.25])
2. It looks like you are trying to reduce the spacing between axes that subplot gives. I gave a similar workaround here that doesn't involve setting the OuterPosition property, but does involve a little fancy subplotting
Hope this helps!
ps - thanks for the well-defined question! :)
  1 Kommentar
Doug
Doug am 29 Apr. 2011
Thanks Jarrod, this helps. I think subplot was fighting the other positioning commands I was trying to use. I wasn't familiar with using the axes command directly, it looks like that offers me the flexibility I was looking for.
Doug

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 29 Apr. 2011
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.
  1 Kommentar
Doug
Doug am 29 Apr. 2011
Yes, I realized I wasn't able to set OuterPosition without affecting Position and vice-versa. Still seems to be strange behavior, but at least you've been able to diagnose what's going on. Thanks!
Doug

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by