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)

 採用された回答

Jan
Jan 2011 年 12 月 10 日

0 投票

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 件のコメント

Eric
Eric 2011 年 12 月 10 日
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
Jan
Jan 2011 年 12 月 11 日
@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.
Eric
Eric 2011 年 12 月 11 日
ah. i must not be able to read on weekends. thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

タグ

質問済み:

2011 年 12 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by