Subplot with odd number of plots

240 ビュー (過去 30 日間)
Davide
Davide 2016 年 4 月 27 日
コメント済み: Hemang Vadgama 2021 年 9 月 29 日
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?

回答 (4 件)

Benyamin Nemati
Benyamin Nemati 2021 年 9 月 26 日
try this
figure
hold on
subplot(3,2,1)
subplot(3,2,2)
subplot(3,2,3)
subplot(3,2,4)
subplot(3,2,5.5)
  5 件のコメント
Benyamin Nemati
Benyamin Nemati 2021 年 9 月 28 日
You're welcome Amal.
Hemang Vadgama
Hemang Vadgama 2021 年 9 月 29 日
Thanks

サインインしてコメントする。


Stephen23
Stephen23 2016 年 4 月 27 日
編集済み: Stephen23 2016 年 4 月 27 日
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.
  3 件のコメント
VIVEKANANDA HAZRA
VIVEKANANDA HAZRA 2021 年 6 月 15 日
handle
Amal AbdelGawad
Amal AbdelGawad 2021 年 9 月 28 日
Thank you.

サインインしてコメントする。


Steven Lord
Steven Lord 2021 年 3 月 26 日
Draw out a 3-by-4 grid of subplot axes. The first two subplots use positions 1-2 and 3-4. The next two use 5-6 and 7-8. The final one uses 10-11. I added two additional subplot axes to show you which spaces are not used.
subplot(3, 4, [1 2])
title('First')
subplot(3, 4, [3 4])
title('Second')
subplot(3, 4, [5 6])
title('Third')
subplot(3, 4, [7 8])
title('Fourth')
subplot(3, 4, [10 11])
title('Fifth')
subplot(3, 4, 9, 'Color', 'r')
title('unused')
subplot(3, 4, 12, 'Color', 'r')
title('unused')

KSSV
KSSV 2016 年 4 月 27 日
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......
  1 件のコメント
Amal AbdelGawad
Amal AbdelGawad 2021 年 3 月 25 日
Could you please tell me what do you mean by "Change positionVector accordingly"?
Because I tried your code but it didn't work.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by