How to get absolute aspect ratio of a figure?
Show older comments
How to get absolute (in screen pixel units) aspect ratio of an existing figure window? or the plotting area?
Answers (1)
Walter Roberson
on 5 Oct 2015
Edited: Walter Roberson
on 5 Oct 2015
I am not sure what an absolute aspect ratio is, but in any case:
fig = handle to graphics container object of interest such as figure
oldunits = get(fig, 'Units');
set(fig, 'Units', 'pixels');
figpos = get(fig, 'Position');
set(fig, 'Units', oldunits);
aspect_ratio = figpos(3)/figpos(4);
2 Comments
Mr M.
on 6 Oct 2015
Edited: Walter Roberson
on 6 Oct 2015
Walter Roberson
on 6 Oct 2015
Setting a figure to 'normalized' [0 0 1 1] does not cover the full screen: full screen hides window decorations and some operating-system imposed margin. If you want full screen then that is a different question than what you get from normalized 0 0 1 1.
The code I provided above finds the window size in pixels and calculates the aspect ratio.
If you want to know the aspect ratio of the screen then,
figpos = get(0,'ScreenSize');
aspect_ratio = figpos(3)/figpos(4);
but only for R2014a and before. For later versions,
figpos = get(groot,'ScreenSize');
aspect_ratio = figpos(3)/figpos(4);
Note that this code does not handle the case of multiple displays. For those I think the code would be
aspect_ratio = figpos(:,3)./figpos(:,4);
Categories
Find more on Annotations 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!