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
Jacob D (2021). JacobD10/tightfigadv (https://github.com/jdonley/tightfigadv), GitHub. Retrieved .
Inspired by: tightfig(hfig)
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Thanks for your work and your recommendation about 'tightPlots'. These 2 tools really help me a lot.
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
'matlab.graphics.shape.internal.AnnotationPane'."
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.
Rico, I have pushed a fix that I think may fix the issue you noticed. Let me know if it solves the problem.
Works with legend, thanks!
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.