recipes : Plotting : Plot Manipulation : Creating multiple panels in one window

Problem

You want to plot multiple panels in one figure window.

Solution

Use the subplot command.

For example:

clf
subplot(1,2,1), plot(rand(1,30))
subplot(1,2,2), hist(randn(1,30))

Subplot makes it easy to arrange your sub-figures in grid. It takes three arguments: the number of rows, the number of columns, and the position of the figure. It is possible for a figure to span rows or columns. For example:

clf
subplot(2,2,1), hist(randn(1,30))
subplot(2,2,3), hist(randn(1,30))
subplot(2,2,[2,4]), plot(rand(1,30))

Discussion

subplot is quick and useful but it isn't the answer to every problem. Plots can only be laid out in a grid format and more complex arrangements (such as a plot within a plot) aren't supported. The spacing between sub-figures is rather large, making subplot inefficient when large numbers of sub-figure are needed. Finally, subplot does not allow figure panels to overlap, so when using it you may run into situations when a panel vanishes unexpectedly even though it should have been plotted. The axes command is more fiddly to use but overcomes these issues.