필터 지우기
필터 지우기

strange behavior (bug?) with subplot and setting outerposition

조회 수: 2 (최근 30일)
Doug
Doug 2011년 4월 29일
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])

채택된 답변

Jarrod Rivituso
Jarrod Rivituso 2011년 4월 29일
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
Doug
Doug 2011년 4월 29일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 4월 29일
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
Doug
Doug 2011년 4월 29일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by