File Exchange

image thumbnail


version 1.2 (122 KB) by

Asymmetric subplots with variable inner gaps and outer margins.

22 Ratings



View License

subtightplot is a merger of Pekka Kumpulainen's tight_subplot and Nikolay S.'s subplot_tight. It extends the former, which supports asymmetric subplots, to allow for variable margins in addition to gaps, as in the latter.

Existing scripts that currently call Matlab's builtin subplot can be adapted with minimal modification by issuing the following command upfront:
  subplot = @(m,n,p) subtightplot(m,n,p,opt{:});
where opt = {gap, width_h, width_w} describes the inner and outer spacings. The screenshot attached shows demo results for examples modified from the subplot documentation.

For axes ticks and labels and locations, see Matlab's axes properties documentation, or try Eran Ofek's subplot1 for a more guided approach.

If you prefer a post-processing solution, see Richard Crozier's tightfig or Aditya's spaceplots.

Alon Geva's subplotplus is interesting for making complicated subplot arrangements; apparently gaps and margins are fixed. Aslak Grinsted's subaxis is based on a richer, more expressive HTML jargon. Joris Kampman's subplot_grid is a colossal 3500+ line object-based implementation. These high-end alternatives are a departure from the built-in subplot's calling syntax, though.

For an overview, please see the Dec 21st, 2012 post on the File Exchange Pick of the Week Blog, titled "Figure margins, subplot spacings, and more…".

Comments and Ratings (26)

Nevermind, my fault.

Any chance to add code that would make the width/height of the subplots equal by default? It's super helpful, but that would be my one request so I didn't have to fiddle with the widths. Perhaps the inequality is caused by my removal of YTickLabels and no YLabel in my 1 x 2 subplot trial.

w rq

w rq (view profile)



Troy (view profile)


Troy (view profile)


JWall (view profile)

Great, thank you!!!


Al (view profile)

just works


Shaun (view profile)

Finally a script very easy to use, basically use the same syntax of subplot!!!

@Erik: yes, it's possible to pass additional input arguments (after the 6 first ones), e.g.:
  figure, subtightplot(3,2,1,[],[],[],'Color','b')
Any property-value pairs are passed on to subplot; the 'replace' input is not supported.

Abhinav Gupta

Thanks a ton!

Very helpful and easy to use.

Yuan Zhou

Very useful. Save me a lot of time. Thanks.

Yuan Zhou


Erik (view profile)

Works great with the suggested function handle. Is it possible to pass more inputs to subplot (see subplot documentation)? I get an error when I try this:

subplot = @(m,n,p,varargin) subtightplot(m,n,p,[],[],[],varargin{:});

and then I get an error if I use e.g. subplot(m,n,p,'replace'). Is it possible to support the various subplot syntaxes in this way? E.g. write subtightplot in such manner that it works like this:

subplot = @(m,n,p,varargin) subtightplot(m,n,p,varargin{:},gap, marg_h, marg_w);

If you then use the same input argument checking as subplot itself uses, you could basically rewrite subplot with the support for gap, marg_h and marg_w.


Martin (view profile)

thank you :-)


Excellent! Thanks a lot

Anton Semechko

Anton Semechko (view profile)

@Tamanaco: clear subplot;


Hi Felipe! How do you revert the
subplot = @(m,n,p) subtightplot(m,n,p,opt{:});
assignment back to the original Matlab subplot function? Regards and thanks!

Excellent utility, and works well with export_fig. I implement it with all of my tools.


K Y (view profile)

really useful for me
many thanks

Very useful. Thought of writing it myself before found this submission.



acknowledging another FX submission.


acknowledged one more FX submission.

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video