我計劃生成一個圖,第一行有 3 個子圖,第二行有 4 個子圖tiledlayout。由于 4 不是 3 的倍數,因此我很難正確管理它。我見過的所有例子都是對齊的子圖(瓷磚)。
通常我會這樣做:
subplot(2,3,1); plot(...);
subplot(2,3,2); plot(...);
subplot(2,3,3); plot(...);
subplot(2,4,5); plot(...);
subplot(2,4,6); plot(...);
subplot(2,4,7); plot(...);
是否可以通過使用來實作這一目標tiledlayout?
uj5u.com熱心網友回復:
方法一:繼續使用 subplot()
如果您想繼續使用該subplot()函式,您可以在這種情況下使用 3 和 4 的最低公倍數 (LCM)。在這種情況下,使用具有 2 行 12 列的子圖網格就足夠了。這種方法的關鍵是讓子圖跨越多個位置。函式中的第三個引數subplot()將決定每個子圖從頭到尾跨越的位置。我發現 subplot 和 span 概念延續到許多語言,這就是我傾向于使用它的原因tiledlayout()。


clf;
subplot(2,12,1:4); plot(rand(5,1));
subplot(2,12,5:8); plot(rand(5,1));
subplot(2,12,9:12); plot(rand(5,1));
subplot(2,12,13:15); plot(rand(5,1));
subplot(2,12,16:18); plot(rand(5,1));
subplot(2,12,19:21); plot(rand(5,1));
subplot(2,12,22:24); plot(rand(5,1));

clf;
subplot(2,12,2:4); plot(rand(5,1));
subplot(2,12,5:7); plot(rand(5,1));
subplot(2,12,8:10); plot(rand(5,1));
subplot(2,12,13:15); plot(rand(5,1));
subplot(2,12,16:18); plot(rand(5,1));
subplot(2,12,19:21); plot(rand(5,1));
subplot(2,12,22:24); plot(rand(5,1));
方法二:使用 tiledlayout()
Grid_Height = 2; Grid_Width = 12;
tiledlayout(Grid_Height,Grid_Width);
Position = 1; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 5; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 9; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 13; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 16; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 19; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 22; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/345205.html
上一篇:迭代地將矩陣添加到更大的矩陣中
下一篇:如何更改圖形視窗的外觀?
