Why does the axis 'Position' property not return the correct values after the size and position are changed?
3 次查看(过去 30 天)
显示 更早的评论
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.
figure
hold on
axis equal
m = 8;
n = 5;
xv = (1:n);
xM = repmat(xv,m,1);
yv = (1:m);
yM = repmat(yv,n,1)';
c = rand(size(xM(:)));
scatter(xM(:),yM(:),[],c)
xspan = max(xM(:)) - min(xM(:));
yspan = max(yM(:)) - min(yM(:));
hax = gca;
psBeforeZoom = get(hax,'Position')
xlim([min(xM(:))-xspan*0.1 max(xM(:))+xspan*0.1])
ylim([min(yM(:))-yspan*0.1 max(yM(:))+yspan*0.1])
psAfterZoom = get(hax,'Position')
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!