File Exchange

image thumbnail


version (4.61 KB) by Jacob D
A MATLAB function to remove white space around figures

1 Download

Updated 12 Dec 2017

From GitHub

View license on GitHub

This MATLAB function removes all excess white space from a figure by searching through child axes, legends, colorbars and text labels to find the outer most objects.
The function extends tightfig() for use with HG2, colorbars, legends and previously moved text labels.
Manually positioning text labels does not update TightInset values and so their equivalent values are computed using Extent values and parent Position values.

Future additions may include support for positioning of annotations, tick labels and tick label exponents.

See also:

Cite As

Jacob D (2021). JacobD10/tightfigadv (, GitHub. Retrieved .

Comments and Ratings (12)

Huaihang Song

Qi Yan

Thanks for your work and your recommendation about 'tightPlots'. These 2 tools really help me a lot.

Qi Yan

Stanislav Steinberg

Hi, in 2018a with f being a handle to a figure with 8 subplots I get:

Error using cellfun
Input #2 expected to be a cell array, was double instead.

Error in tightfigadv (line 64)
origtxparunits = cellfun(@(x) x.Units, htxPar, 'un', 0);


Hi, i'm trying to use your function (thank you in advance). However i'm getting the next error:

"Error in tightfigadv (line 64)
origtxparunits = cellfun(@(x) x.Units, htxPar, 'un', 0);
No appropriate method, property, or field 'Units' for class

Evert Merkx

Jacob D

Hi Vince, you could try another FileExchsnge submission called tightPlots. It allows you to adjust the gaps between subplots along with various other parameters. I often use it with tightfigadv and it works great.

Vince Clementi

Great program. However, I'm noticing this does not remove the space between subplots, only outside of the subplots...any suggestions on how to do this? Thanks.

Jacob D

Rico, I have pushed a fix that I think may fix the issue you noticed. Let me know if it solves the problem.

Leon Aksman

Works with legend, thanks!

Jacob D

Hi Rico, could you raise an issue on the GitHub page with a minimum working example? I’ll then have a look into it for you! Thanks


I have a 4 row subplot, with colorbars only on the bottom two subplots. I found that this code cut the colorbars off just as the original tightfig did. Not sure if this happens to anyone else. Thanks.

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

Inspired by: tightfig(hfig)

Community Treasure Hunt

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

Start Hunting!