MATLAB: Get(axH,’position’) reporting incorrect values

axesposition;

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)

Best Answer

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.