Subplots made by multiple plots
1 回表示 (過去 30 日間)
古いコメントを表示
Laurens
2011 年 12 月 28 日
回答済み: Demetrio Rodriguez Tereshkin
2016 年 2 月 23 日
Hi,
I would like to draw a figure consisting of 3 subplots, each made by 4 plots.
Here's my code, to make it more clear...
hold all;
for i=1:4
subplot(1,3,1);
plot(S1(:,1,i), S1(:,2,i), c(i));
xlim([0 1]);
subplot(1,3,2);
plot(S2(:,1,i), S2(:,2,i), c(i));
xlim([0 1]);
subplot(1,3,3);
plot(S3(:,1,i), S3(:,2,i), c(i));
xlim([0 1]);
end
hold off;
My problem is that only the last plots are drawn in the subplots. So I see only one line per subplot, instead of the 4 I intended. Can anyone help me fix this?
Thanks!
0 件のコメント
採用された回答
Sean de Wolski
2011 年 12 月 28 日
Each subplot needs to be held individually.
figure; hold on
subplot(121)
hold on
plot(1:3)
plot(rand(1,3))
subplot(122)
hold on
plot(4:6)
plot(rand(1,3))
0 件のコメント
その他の回答 (1 件)
Demetrio Rodriguez Tereshkin
2016 年 2 月 23 日
Or just use hold on after subplot.
% some values
x(1,:) = 1:10;
x(2,:) = x(1,:)-1;
y = x.^2;
% subplots in a loop replace each other
fig1 = figure('Name', 'subplots_replacement');
for i = 1:2
subplot(1, 2, 1)
plot(x(i,:))
subplot(1, 2, 2)
plot(y(i,:))
end
% subplots in a loop overlap
fig2 = figure('Name', 'subplots_add');
for i = 1:2
subplot(1, 2, 1)
hold on % this helps
plot(x(i,:))
subplot(1, 2, 2)
hold on % this helps
plot(y(i,:))
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!