Subplots made by multiple plots
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Laurens
le 28 Déc 2011
Réponse apportée : Demetrio Rodriguez Tereshkin
le 23 Fév 2016
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 commentaires
Réponse acceptée
Sean de Wolski
le 28 Déc 2011
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 commentaires
Plus de réponses (1)
Demetrio Rodriguez Tereshkin
le 23 Fév 2016
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 commentaires
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!