File Exchange

image thumbnail


version (5.99 KB) by Theo Michelis
Plots and subplots with adjustable margins, gaps, axis aspect ratio and figure size.


Updated 06 Mar 2015

View Version History

View License

tightPlots is a function that allows making single plots or subplots with controlled size and margins. The desired (page) width, aspect ratio and margins must be input, with which the appropriate height is calculated.

This workflow allows for all figures to maintain font formatting when they are inserted into a document/publication. Adjust the width to match the document page width and fix the font size. Narrow plots can then be created by Setting wide side margins.
The function additionally creates a bounding box equal to the figure size on the screen. As a result, what is seen on the monitor can be printed in both raster (.png) and vector (.eps, .pdf) formats with the same result.

tightPlots has been influenced by the "tight_subplot" function of Pekka Kumpulainen, hence, parts of the code and parameter names were kept the same.

Cite As

Theo Michelis (2021). tightPlots (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Robert Rous

Jon Adsersen

Very nice function.

One little thing: Seems to me preallocation og axes in line 144 should be:
ha = gobjects(Nh*Nw,1);
In stead of:
ha = zeros(Nh*Nw,1);

ziyong han

Qi Yan

Very helpful for producing good-looking figures! Thanks a lot.


Useful submission! In HG2 versions of MATLAB, the returned values should be of type `handle` and not `double`.

almog shalom

Nice function.
But it needs a slight modification for the new graphics system of post-2014b versions.

Rahim Rezaeiha

Great function!
Works very well for publications.


Very useful and convenient function, thanks a lot


This function is awesome, finally I can stop using the stupid subplot function!


Clean and easy to use for publication purposes.

Theo Michelis

It is not supposed to resize a figure. Rather, you create a figure with the desired width for your document and then fill it with axes.


This function does not do figure resize, it cuts off tick labels, code comments are non -standard (H1 line), ....

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

Community Treasure Hunt

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

Start Hunting!