Axes' position after adjusting data aspect ratio

조회 수: 5 (최근 30일)
Ellen
Ellen 2013년 1월 3일
When adjusting the data aspect ratio of axes, the visual display of the axes changes, but not their 'Position'. Is it possible to find the equivalent position of the adjusted/visible axes? Needed for e.g. annotations and for positioning new axes/subplots in the same figure.
Here is an illustration (black - aspect adjusted, red - position):
figure;
axpos1 = get(gca,'Position')
set(gca,'DataAspectRatio',[1 1 1]);
axpos2 = get(gca,'Position')
axes('Position',axpos2,'Color','None','XColor','r','YColor','r');

채택된 답변

José-Luis
José-Luis 2013년 1월 3일
편집: José-Luis 2013년 1월 3일
What happens is that the axes object is not actually the white square you see. If you go to the property editor and click on both axes you will see that both axes actually have the same size.
If you want to keep the Position so your annotation make sense, you could do it in two ways:
  • Define a custom axes size so that knowing your XLim and YLim you could get the aspect ratio you want
  • Calculate the position, given the aspect ratio, of the white square within the axes object
However, maybe someone has done this in the file exchange but I can't remember off the top of my head.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2013년 1월 3일
The InnerPosition property, possibly?

Ellen
Ellen 2013년 1월 3일
Thanks to both! I found a file exchange function that solves the problem: http://www.mathworks.com/matlabcentral/fileexchange/9615, using a combination of Position, DataAspectRatio and PlotBoxAspectRatio.
I noticed that the default data aspect ratio was [1 1 1], and was puzzled to see that it would still change when I applied the third line - and that the axes obviously didn't look like [1 1 1] before doing so. Any explanation?
  댓글 수: 1
José-Luis
José-Luis 2013년 1월 3일
편집: José-Luis 2013년 1월 3일
By default the behavior of the axes is stretch to fill. Setting the dataAspectRatio overrides that. It's not very logical, if you ask me.
Please accept an answer if it helped you.

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

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by