Wednesday, January 30, 2013

Modify the space between MATLAB subplots

Sometimes, the MATLAB function subplot reserves too much space and destroys the appearance of the plot. Therefore, it is necessary to adjust the space between the subplots and between the subplots and the boarder.
The subplot function itself provides the command:
subplot('Position',[left bottom width height]) 

It creates an axes at the position specified by a four-element vector. Note that they are in normalized coordinates in the range from 0.0 to 1.0. If only minor change of the space is required, this approach is appropriate. The following is an example showing how to increase the width of the subplot.

h = subplot(2,3,2);
p = get(h, 'position');
p(3) = p(3) + 0.02;
set(h, 'position', p);

However, the adjustment of one subplot may affect other plots. Thus it is a good idea to have a general subplot arrangement beforehand. In this situation, we can use axes to create the axes graphics object. The function axes accepts the four-element vector as its position.

axes('Position',[left bottom width height])

Pekka Kumpulainen has published a “tight subplot” function to MATLAB File Exchange. It gives you the control of subplot spacing. The file can be found at

No comments:

Post a Comment