How to plot 17 subplots?

19 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 6 月 29 日
コメント済み: NIKHIL THOPPIL 2019 年 8 月 16 日
I am trying to plot a large number of subplots, but want to make sure formartting is such that it takes the most compact form (instead of having 1 row with 17 plots, 2 rows, with 13 and 14 plots, etc). So in this case, I would like 5 rows of plots with 4 plots in each row and 1 in the last row. If 16 plots are selected, then 4 rows with 4 plots, etc.
  2 件のコメント
Adam
Adam 2017 年 6 月 30 日
Depending on what you are plotting you are probably better of creating your own axes and positioning them in the desired pattern than using subplot. If you don't want x and y tick labels for every plot subplot creates a lot of wasted space around the axes.
Jan
Jan 2017 年 6 月 30 日
編集済み: Jan 2017 年 6 月 30 日
Some explicite examples for Adam's suggestion: FEX: Search for "subplot"
I would like 5 rows of plots with 4 plots in each row and 1 in the last row.
These are 21 plots, not 17. What about 4 rows and 5 columns with two diagrams in the last row for 17 diagrams?

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

採用された回答

John BG
John BG 2017 年 6 月 29 日
Hi Ibro
let be N the amount of images, then the most compact, square-like lay-out is achieved with
L=ceil(N^.5)
for k=1:1:N
subplot(L,L,k)
plot(..) or stem(..) or any other plot type
end
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
  1 件のコメント
John BG
John BG 2017 年 6 月 30 日
Ibro
the thing with subplot and a large amount if images is that the area for each image is reduced, therefore losing visual resolution.
One way around would be to plot 17 separate figures
for k=1:1:17
hf=figure(k)
plot(..) or stem(..) or any other plot type
hf.Position=[left down width height]
end
Usually top left corner of the screen is [0 0].
capturing the figure handle you can save further space, away from things not needed, to give more space for the images
hf=figure
hf.ToolBar='none'
Another way would be to group the figures in groups of 4, reducing the amount of needed figures to
N=17
for k=1:1:floor(N/4)
figure(k)
for s=1:1:4
subplot(2,2,s)
plot(..) or stem(..) or any other plot type
end
end
for k=(N-floor(N/4)):1:N
figure(k)
for s=1:1:(N-floor(N/4))
subplot(2,2,s)
plot(..) or stem(..) or any other plot type
end
end
regards
John BG

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

その他の回答 (1 件)

Jan
Jan 2017 年 6 月 30 日
編集済み: Jan 2017 年 6 月 30 日
This adds a new row only if required:
N = 17;
figure;
nS = sqrt(N);
nCol = ceil(nS);
nRow = nCol - (nCol * nCol - N > nCol - 1);
for k = 1:N
subplot(nRow, nCol, k);
plot(1:10, rand(1, 10));
end
Comparison to the pure square solution: Saving an empty row helps to get the "most compact form", which is not a 5x5 arrangement:
See also:
  1 件のコメント
NIKHIL THOPPIL
NIKHIL THOPPIL 2019 年 8 月 16 日
Thank you

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

カテゴリ

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