필터 지우기
필터 지우기

Use subplot command to make 3+ Vertically Stacked Plots

조회 수: 115 (최근 30일)
AmericanExpat26
AmericanExpat26 2016년 9월 17일
답변: Steven Lord 2019년 6월 14일
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.
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?

채택된 답변

Star Strider
Star Strider 2016년 9월 17일
Try this:
figure(1)
subplot(3,1,1)
plot(...)
subplot(3,1,2)
plot(...)
subplot(3,1,3)
plot(...)
  댓글 수: 2
AmericanExpat26
AmericanExpat26 2016년 9월 17일
Many thanks. Star Strider. In hindsight, this was a real 'duh' moment after reading the answer.
Star Strider
Star Strider 2016년 9월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Gustavo
Gustavo 2016년 12월 8일
Hi, how did you remove the space between the subplots?
  댓글 수: 1
Alejandro
Alejandro 2017년 9월 11일
편집: Alejandro 2017년 9월 11일
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
Steven Lord 2019년 6월 14일
This question was asked before this function existed, but if you're using release R2018b or later try the stackedplot function.

Habtamu Tesfaw
Habtamu Tesfaw 2019년 6월 14일
Can't understand the accepted answer. Where is the stacking command then? please help me

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by