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.
Best Answer