Why does the axis 'Position' property not return the correct values after the size and position are changed?
5 views (last 30 days)
I first plot data using the scatter function, and then set the x-axis and y-axis limits. I have the axis limits and style set to 'equal', so when the limits are changed, the size of the plotting area is automatically changed to maintain the correct aspect ratio.
The problem is that when I query the axis position and size after that, the result does not match the new size or position. Instead it returns the same size and position of the axis before the inner plot size was changed.
According to the documentation linked below, I believe I should be able to query the axis 'Position' property to get the size of the actual plot area (blue border in the diagram shown in the linked documentation page). But seems to either not be updating, or it's returning the size and position of some other object instead.
Below is a working example that reproduces my problem. If a breakpoint is set right before the xlim is changed, you can watch the actual size of the inner plot change. Note that the results of the 'Position' queries are [incorrectly] the same.
m = 8;
n = 5;
xv = (1:n);
xM = repmat(xv,m,1);
yv = (1:m);
yM = repmat(yv,n,1)';
c = rand(size(xM(:)));
xspan = max(xM(:)) - min(xM(:));
yspan = max(yM(:)) - min(yM(:));
hax = gca;
psBeforeZoom = get(hax,'Position')
psAfterZoom = get(hax,'Position')