I can get the position of the axis easily
figure,plot([0 1], [0 1])
axis equal
AxesHandle=findobj(gcf,'Type','axes');
get(AxesHandle,'Position')
However when I modify the axis limits the axis position does not update.
axis tight
get(AxesHandle,'Position')
still gives me the same answer. How do I get the correct axis position in the second case?

 채택된 답변

Matt Fig
Matt Fig 2011년 4월 20일

2 개 추천

What changes is the tightinset property and plotboxaspectratio.
figure,plot([0 1], [0 1])
axis equal
AxesHandle=findobj(gcf,'Type','axes');
pt1 = get(AxesHandle,{'Position','tightinset','PlotBoxAspectRatio'});
pt1{:}
axis tight
pt2 = get(AxesHandle,{'Position','tightinset','PlotBoxAspectRatio'});
pt2{:}

댓글 수: 4

Paulo Silva
Paulo Silva 2011년 4월 20일
Interesting information, +1 vote
dk
dk 2011년 4월 20일
This was helpful. However in the case below the distance from the plot area to the edge of the figure is changing. However neither the position nor the tightinset properties are changing.
figure,plot([0 1], [0 1])
set(gcf,'position', [ -1904 468 1831 420])
axis equal
axis tight
AxesHandle=findobj(gcf,'Type','axes');
pt1 = get(AxesHandle,{'Position','tightinset'}); % [left bottom right top]
pt1{:}
set(gcf,'position', [ -1904 468 793 420])
pt2 = get(AxesHandle,{'Position','tightinset'});
pt2{:}
Matt Fig
Matt Fig 2011년 4월 20일
All you are doing here is moving the figure around. Of course this doesn't change the axes properties! Why would you think that moving the figure around would change the axes properties?
Also, you can use GCA to get the axes handle, just like GCF gets the figure handle...
Matt Fig
Matt Fig 2011년 4월 20일
If you want to get the distance between the edge of the figure and the axis plot area, you need to stop using normalized units and switch to pixels. Then you will see a change.....
figure,plot([0 1], [0 1])
set(gcf,'position', [104 468 1831 420])
axis equal
axis tight
set(gca,'units','pix')
pt1 = get(gca,{'Position','tightinset'}); % [left bottom right top]
set(gca,'units','norm')
pt1{:}
input('Hit return to continue...');
set(gcf,'position', [104 468 793 420])
set(gca,'units','pix')
pt2 = get(gca,{'Position','tightinset'});
set(gca,'units','norm')
pt2{:}

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

추가 답변 (2개)

Kelly Kearney
Kelly Kearney 2011년 4월 20일

8 개 추천

I wrote a little function that analyzes the aspect ratios and calculates the plotted axis region:
Should return exactly what you're looking for.

댓글 수: 2

dk
dk 2011년 4월 20일
Thank you. You are right, this is what I was looking for.
Yujendra Mitikiri
Yujendra Mitikiri 2021년 10월 23일
편집: Yujendra Mitikiri 2021년 10월 23일
Thank you! This is exactly what I needed, in order to add annotations after making "axis equal."

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

Paulo Silva
Paulo Silva 2011년 4월 20일

0 개 추천

The position remains the same, don't believe me? go to Tools and press Edit Plot, now click on the axis :)
One thing that do change is the:
xlim

댓글 수: 1

dk
dk 2011년 4월 20일
I know the matlab axis position property is not changing. What I want is the position of the actual plotting area.

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

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

dk
2011년 4월 20일

편집:

2021년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by