get(gca,'DataAspectRatio') does not refelct the real pixel ratio, and does not upate after stretching the figure window in default auto mode.
2 views (last 30 days)
Show older comments
Hi, I am using imagesc to show a matrix and want to get the aspect ratio of pixels at that time:
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(C)
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000] looks not close enough to real display.
aMode = get(gca,'DataAspectRatiomode') %auto
% however, after set the aspect ratio to its original value, the display changed:
set(gca,'DataAspectRatio',a)
% The initial aspect ratio value [2.0000 1.5000 1.0000] is more close to the 2nd image.
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(C)
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000]
aMode = get(gca,'DataAspectRatiomode') %auto
% I stretch the window, then retrieve the ratio again, but it still the same
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000]
Why the initial retrieved aspect ratio does not reflect the displayed image and it does not update?
Thanks.
0 Comments
Answers (1)
Walter Roberson
on 20 Oct 2023
set(gca,'DataAspectRatio',a)
when you set the DataAspectRatio then DataAspectRatioMode is set to 'manual' -- but the mode must be 'auto' in order for stretch-to-fill behaviour to be active. This is pointed out clearly in daspect
0 Comments
See Also
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!