placeFig, a FigureGrid command aware of screen size

A useful command to create a figure-grid of matlab figures tidily distributed across the screen
41 Downloads
Updated 11 Jul 2023

View License

function placefig_Normalized(fig,m,n,k)
% PLACEFIG(fh,m,n,k) - puts figure fh in position k of a (m x n) array of figures on the screen.
% ------------------------------------
% placefig_Normalized(fig,m,n,k)
% ------------------------------------
% m x n picture matrix, set at location k, row-wise-counting
% k (m=2,n=3) x(n) y(m)
% 1 2 3 1 2 3 1 1 1
% 4 5 6 1 2 3 2 2 2
%
% Figure is resized to fit in the viewport at the indicated location k
%
% EXAMPLE: put figure to cover top half of the screen
% figure(31);
% placefig(31, 2,1,1);
%
% EXAMPLE: put figure to cover top/left quarter of the screen
% figure(31);
% placefig(31, 2,2,1);
%
% EXAMPLE: grid of 2x3 figures fill up first 4
% figure(31);figure(32);figure(33);figure(34);
% placefig(31, 2,3, 1);
% placefig(32, 2,3, 2);
% placefig(33, 2,3, 3);
% placefig(34, 2,3, 4);
%
% ------------------------------------
% Set-up settings calls (one argument)
% ------------------------------------
% placefig_Normalized(1)
% placefig_Normalized(0)
% placefig_Normalized(-k)
% ------------------------------------
% placefig_Normalized(-k) : Select monitor number k
% placefig_Normalized(1) : no margins top and bottom%
% placefig_Normalized(0) : reset margins top and bottom
%
% Issue about using pixels with monitor beyond nr 1:
% -------------------------------------------------
% If you specify a monitor other than primary one (-1), it will go to pixel units;
% If you connected|disconnected HDMI without restarting Matlab afterwards
% it will go out of screen.
% Solution 1: placefig(-1) will reset main monitor and overcome this but go to monitor 1
% Solution 2: restart matlab after you change the nr monitors connected
% -------------------------------------------------
%
%
% rev.5.1, Massimo Ciacci, July 11, 2023
% note: better to place the figure immediately after creation, before plotting onto it, it works faster.
%
% note: since matlab is uncapable to refresh monitor status after plugging or unplugging monitors
% we cannot rely on pixel size that much, thereby we changed to normalized units, in the hope
% that the underlying Java scaler is able to keep up to date and avod tiny figures on Laptop displays.
%
% this however won't work with secondary monitors.
%
% =================================================================================================
% #### SUGGESTION: IN WINDOWS, DISPLAY SETTINGS, SET MAIN MONITOR = YOUR EXTERNAL LARGE SCREEN
% =================================================================================================
% If you have your laptop as main monitor accept the consequences (tiny figures on laptop screen)

Cite As

Massimo Ciacci (2024). placeFig, a FigureGrid command aware of screen size (https://www.mathworks.com/matlabcentral/fileexchange/72807-placefig-a-figuregrid-command-aware-of-screen-size), MATLAB Central File Exchange. Retrieved .

getScreenSizeFunc is based on Ulrik' answer in : https://nl.mathworks.com/matlabcentral/answers/312738-how-to-get-real-screen-size

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: PlotLogCompand

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
5.1.0

Support 2nd or Nth monitor for output.

5.0.0

No need to fiddle with pixel size, rather use normalized units.

4.0.0

Cleaned up code, added a ultra-tall flag toggle to reduce margins.

3.0.0