get(axH,'position') reporting incorrect values?

hi all. it appears that getting an axes 'position' will sometimes report incorrect values.
here is how i produce reliably:
figure;ax1 = axes('xcolor','m','ycolor','m');
ax2 = axes('position',[0 0 1 1],'color','none');
rPosition = rectangle('parent',ax2,'position',get(ax1,'position'),'edgecolor','k');
rectangle shows up in wrong place:
but if i subsequently draw a rectangle at outerposition, all of a sudden the position/black rectangle is in the right place:
rOuter = rectangle('parent',ax2,'position',get(ax1,'outerposition'),'edgecolor','r');
edit: actually drawing any subsequent rectangle in ax2 in a position set as either get(ax1,'outerposition') or 'tightinset' will re-position the first rectangle properly
interestingly, if i get(ax1,'position') before and after the second rectangle is drawn i get the same values:
[0.1300 0.1100 0.7750 0.8150]
ideas? thanks
7.9.1.671 (R2009b) Service Pack 1 (linux 64bit)

 采纳的回答

I see -and expect- the same behaviour under Matlab 6.5/2009a/2011b under Windows.
Drawing the rectangle in the ax2 object causes an automatic scaling of the X- and Y-limits. Therefore the visible position is shifted. You can avoid this by setting the limits explicitely:
figure;
ax1 = axes('xcolor', 'm', 'ycolor', 'm');
ax2 = axes('position', [0 0 1 1], 'color', 'none', ...
'XLim', [0, 1], 'YLim', [0, 1]);
rectH = rectangle('parent', ax2, ...
'position', get(ax1,'position'), ...
'edgecolor','k');
This behaviour explains also, why the subsequent drawings seem to fix the problem - it happens by accident by resetting the limits to the necessary size.

3 个评论

thanks for explaining this behavior. i can see this is try by monitoring x/ylim. but i still don't understand why matlab would do this.
the defaults for xlim and ylim in this case are [0 1] same as you explicitly set.
after the first rectangle is drawn they are indeed scaled as you say:
get(ax2,'xlim') -> [0.1 0.1]
(ylim) is now also the same as new xlim
but these don't make any sense as the position of the rectangle is:
get(rPosition,'position')
ans =
0.1300 0.1100 0.7750 0.8150
what am i missing? or is this indeed a bug as i see it right now
@Eric: I assume a typo: The limits of ax2 are [0.1, 1.0].
This is the intented auto-scaling. Matlab chooses "nice" limits at powers of 10 or multiples of them. Try this:
figure; AxesH = axes; line([0.13, 0.13+0.775], [0.11, 0.11+0.815]); drawnow; get(AxesH, 'XLim')
Again you see that the limits are set to [0.1, 1.0] with auto-scaling and an object with a position of [0.13, 0.11, 0.775, 0.815]. I do neither see an unexpected behaviour nor a bug.
ah. i must not be able to read on weekends. thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by