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!