File Exchange

image thumbnail

subtightplot

version 1.2.0.0 (122 KB) by Felipe G. Nievinski
Asymmetric subplots with variable inner gaps and outer margins.

109 Downloads

Updated 08 Jan 2013

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…".

Cite As

Felipe G. Nievinski (2019). subtightplot (https://www.mathworks.com/matlabcentral/fileexchange/39664-subtightplot), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (58)

i have an array of 4by8 total 30 elements. How to use this function in subplot ?

ALLEN

Better than tight_subplot.
subtightplot can be used with hold on; while tight_subplot can not.

qaqcvc

Thanks! it works

CHEERS! Massive help when plotting

Beat Braem

I like it a lot, but it took me a while to figure out how to properly set the margins between the plots

Mao Ye

thanks a lot

savvasgk

Greg Pittam

Excellent! I've been wanting this for a long time and it's been here all along!

Yijun ZHOU

Highly recomend, it actually works and stops matlabs horrible plotting habbits

Thanks a lot man! I've been looking for this for a while!

Guru Shifu

Shruthi N V

Shruthi N V

Soojong Pak

ZIhui Zhang

David Huynh

M Schmidt

Jörg

Very usefull and easy to use!

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

Great!

HiWave

HiWave

JWall

Great, thank you!!!

Al

just works

Shaun

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.

Thanks a ton!

Very helpful and easy to use.

Yuan Zhou

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

Yuan Zhou

Erik

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

thank you :-)

schwarzkater

Excellent! Thanks a lot

@Tamanaco: clear subplot;

Tamanaco

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

really useful for me
many thanks

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

Updates

1.2.0.0

acknowledging another FX submission.

1.1.0.0

acknowledged one more FX submission.

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