Use subplot command to make 3+ Vertically Stacked Plots
143 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
AmericanExpat26
le 17 Sep 2016
Réponse apportée : Steven Lord
le 14 Juin 2019
I am trying to a plot of 3-4 vertically stacked subplots showing different quantities on the y-axis, but with the same x-axis. I use subplot(2,1,1) and (2,1,2) for the first and second plot. I try but subplot(2,1,3) for the third plot, but MATLAB returns an error - "Index exceeds number of subplots." In various publications, I have seen 3+ vertically stacked plots using the same x-axis like the one below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156422/image.jpeg)
Is this not possible without the creation of a second figure? Also, is there a shortcut to possibly combining subplots from two separate figures to accomplish this?
0 commentaires
Réponse acceptée
Star Strider
le 17 Sep 2016
Try this:
figure(1)
subplot(3,1,1)
plot(...)
subplot(3,1,2)
plot(...)
subplot(3,1,3)
plot(...)
2 commentaires
Star Strider
le 17 Sep 2016
My pleasure.
There are no ‘duh’ moments, only opportunities to learn more. With R2016b now available, those opportunities will increase, since the release notes promise even more functionality.
Plus de réponses (3)
Gustavo
le 8 Déc 2016
Hi, how did you remove the space between the subplots?
1 commentaire
Alejandro
le 11 Sep 2017
Modifié(e) : Alejandro
le 11 Sep 2017
You select the mouse pointer icon and select a subplot, you can now move them closer using the arrow keys. It took me so long to figure that out, it is kind of annoying that there's no easy way built in matlab to programmatically do this kind of stacked plot that share the same x-axis data.
Steven Lord
le 14 Juin 2019
This question was asked before this function existed, but if you're using release R2018b or later try the stackedplot function.
0 commentaires
Habtamu Tesfaw
le 14 Juin 2019
Can't understand the accepted answer. Where is the stacking command then? please help me
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!