Subplots made by multiple plots
1 次查看(过去 30 天)
显示 更早的评论
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!