How to get absolute aspect ratio of a figure?

How to get absolute (in screen pixel units) aspect ratio of an existing figure window? or the plotting area?

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Oct. de 2015
Editada: Walter Roberson el 5 de Oct. de 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 comentarios

Mr M.
Mr M. el 6 de Oct. de 2015
Editada: Walter Roberson el 6 de Oct. de 2015
What is absolute aspect ratio?
Example:
Making full screen:
figure('units','normalized','outerposition',[0 0 1 1]);
Here 1:1 is not so informative, so I want the absolute aspect ratio in pixels = aspect ratio of the full screen.
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);

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Oct. de 2015

Comentada:

el 6 de Oct. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by