Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the borders around subplots in matlab? [duplicate]

Tags:

matlab

subplot

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 end 

Example of wasted white space in subplots

over 50% of the space on the figure is wasted as "blank" I'd like to shrink that blank space down, but have been unsuccessful to identify a mechanism to do so. Thoughts?

like image 788
John Avatar asked Jul 13 '11 20:07

John


People also ask

How do I remove spaces between subplots in Matlab?

Padding = 'none'; t. TileSpacing = 'none'; Note that the last two commands get rid of all the space between the tiled plots.

How do I make subplots different sizes Matlab?

It's possible to make subplots of different sizes by specifying a multiple-element vector for the grid position argument p in the syntax subplot(m,n,p) . Show activity on this post. You can add 4 axeses to the figure, and set the position of each axes: I = imread('cameraman.

How do you split a subplot in Matlab?

subplot( m , n , p ) divides the current figure into an m -by- n grid and creates axes in the position specified by p . MATLAB® numbers subplot positions by row. The first subplot is the first column of the first row, the second subplot is the second column of the first row, and so on.


2 Answers

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 end 

enter image description here

like image 152
nibot Avatar answered Oct 14 '22 15:10

nibot


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.

like image 42
Nicolas Renold Avatar answered Oct 14 '22 16:10

Nicolas Renold