# Subplot with odd number of plots

375 views (last 30 days)
Davide on 27 Apr 2016
Edited: Stephen Cobeldick on 27 Apr 2016
I want a figure with five subplots. Here and there I have found this solution:
subplot(3,2,1), plot(...)
subplot(3,2,2), plot(...)
subplot(3,2,3), plot(...)
subplot(3,2,4), plot(...)
subplot(3,2,[5,6]), plot(...)
It does not work for me because it creates a very large plot at the bottom of the figure, while I would like to have all the five plots of the same dimension, but with the fifth one at the bottom-center of the figure. Any suggestion?

KSSV on 27 Apr 2016
subplot(3,2,1)
subplot(3,2,2)
subplot(3,2,3)
subplot(3,2,4)
positionVector = [0.3, 0.1, 0.3, 0.2];
subplot('Position',positionVector2)
Change positionVector accordingly......

Stephen Cobeldick on 27 Apr 2016
Edited: Stephen Cobeldick on 27 Apr 2016
Here is some simple code that adjusts the position without using any hardcoded values: it centers the last axes based on the positions of the first two axes (and is easy to adjust to more columns):
h(1) = subplot(3,2,1);
h(2) = subplot(3,2,2);
h(3) = subplot(3,2,3);
h(4) = subplot(3,2,4);
h(5) = subplot(3,2,5); % the last (odd) axes
pos = get(h,'Position');
new = mean(cellfun(@(v)v(1),pos(1:2)));
set(h(5),'Position',[new,pos{end}(2:end)])
and it creates this figure: You could also experiment with adjusting the OutsidePosition axes property.