placeFig, a FigureGrid command aware of screen size

A useful command to create a figure-grid of matlab figures tidily distributed across the screen

29 Downloads

Updated 1 Feb 2021

View License

function placefig(fig,m,n,k, forcedW, forcedH, setVirtualScreenSize, ws,hs)
% PLACEFIG(fh,m,n,k,varargin) - puts figure fh in position k of a (m x n) array of figures on the screen.
%
% 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
% Actual screen size and possible OS (windows) scaling is calculated
%
% PLACEFIG([],[],[],[], [], [], 1, w, h)
% Set virtual screen size to w x h pixels. Call it before the ordinary placefig command,
% to use only a portion of the screen for plotting
%
% 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 figuresfill 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);
%
% EXAMPLE: force figure size in pixels
% figure(31);
% placefig(31, 2,2,1,800,600)
%
% EXAMPLE: keep original figure size, yet put them on a grid
% figure(31);figure(32);figure(33);figure(34);
% placefig(31, 2,3, 1j);
% placefig(32, 2,3, 2j);
% placefig(33, 2,3, 3j);
% placefig(34, 2,3, 4j);
%
% rev.3, Massimo Ciacci, September 19, 2019
% note: better to place the figure immediately after creation, before plotting onto it, it works faster.
==========================
function [ Monitor1, MonitorPositions ] = getScreenSizeFunc()
%GETSCREENSIZEFUNC()
% Returns the actual size in pixel of the main monitor
% based on Ulrik' answer in : https://nl.mathworks.com/matlabcentral/answers/312738-how-to-get-real-screen-size

Cite As

Massimo Ciacci (2023). 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
4.0.0

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

3.0.0