File Exchange

image thumbnail

JacobD10/tightfigad​v

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

4 Downloads

Updated 12 Dec 2017

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:
https://au.mathworks.com/matlabcentral/fileexchange/34055-tightfig

Comments and Ratings (12)

Qi Yan

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

Qi Yan

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);

Fernando

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
'matlab.graphics.shape.internal.AnnotationPane'."

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.

https://au.mathworks.com/matlabcentral/fileexchange/45380-tightplots

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

Rico

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
Acknowledgements

Inspired by: tightfig(hfig)