Title: How to reduce the borders around subplots in matlab?
Tags: matlab;subplot
Question: In matlab, an inordinate amount of space is wasted around subplots.  For example, in this example:
t = 0:0.001:2*pi+0.001;
figure(2);
for i = 1 : 25;
subplot(5,5,i);
plot(t, sin(i*t));
axis off
over 50% of the space on the figure is wasted as &quot;blank&quot;  I'd like to shrink that blank space down, but have been unsuccessful to identify a mechanism to do so.  Thoughts?
Comment: Note:  As of 2019b, Mathworks has solved this problem with the tiledlayout command.

Comment: Here is a list of other possible solutions: [tight subplot](http://www.mathworks.com/matlabcentral/fileexchange/27991-tight-subplot), [jointfig.m](http://www.mathworks.com/matlabcentral/fileexchange/304-jointfig-m), [Some Matlab tricks for making figures](http://nibot-lab.livejournal.com/73290.html), [Useful little utility](http://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/5706e8dfbb4a418/f5154f1df6efaff4), [Reduce Grey Space around Images in a Figure](http://www.mathworks.com/matlabcentral/answers/6254-reduce-grey-space-around-images-in-a-figure)

Here is the accepted answer: The subaxis function on the File Exchange allows you to specify margins for subplots.
Example usage:
t = 0:0.001:2*pi+0.001;
figure(2);
for i = 1 : 25;
subaxis(5,5,i, 'Spacing', 0.03, 'Padding', 0, 'Margin', 0);
plot(t, sin(i*t));
axis tight
axis off

Here is another answer: You can position them yourself (or programatically) using
subplot('Position',[left bottom width height]);
By default, the coordinates are normalized. So a position
of [0.1 0.1 0.5 0.5] will start at 10% of the way in
from the lower left corner, and will have a width equal
to half the figure width, and a height equal to half the
figure height.
See the accepted answer for a built-in solution to margins and padding.

Here is another answer: Try to reduce the default values in the hidden axes LooseInsets property, as described in http://UndocumentedMatlab.com/blog/axes-looseinset-property/
For example:
set(gca, 'LooseInset', get(gca,'TightInset'))
Comment for this answer: Does LooseInset work with subplots ?
Comment for this answer: the extra space is taken up by the hidden X & Y axes tick labels, and I do not believe they can be eliminated. But you can improve the situation as follows:
`figure(2); for i = 1 : 25; hax=axes(); plot(t, sin(i*t)); axis tight; axis off; rowIdx=fix((i-1)/5); colIdx=mod(i-1,5); newPos=[.2*colIdx,0.8-.2*rowIdx,.2,.2]; set(gca,'outer',newPos), end`
Comment for this answer: At least in my example, this does nothing on 2011a.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2011:00:07/13/11', 'FavoriteCount': 20.0, 'PostTypeId': 1, 'Tags': '<matlab><subplot>', 'Title': 'How to reduce the borders around subplots in matlab?', 'ViewCount': 65770, 'id': 6685092, 'user_AboutMe': None, 'user_AccountId': 37473.0, 'user_DisplayName': 'John', 'user_Reputation': 5595.0, 'user_Views': 430.0, 'user_id': 107122.0}}