How to select legend in multiple subplot?

조회 수: 2 (최근 30일)
Fahmy Shandy
Fahmy Shandy 2019년 12월 18일
편집: Fahmy Shandy 2019년 12월 18일
And Suppose i have 3 programs in one script. I have 4 subplot and each subplot holds 3 graph. In total, so i have 12 graph.
And i'm graphing them in each program instead of at the same paragraph.
For example :
(first program)
subplot(2,2,1)
plot(x,S)
hold on
subplot(2,2,2)
plot(x,E)
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
(second program)
subplot(2,2,1)
plot(x,S)
subplot(2,2,2)
plot(x,E)
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
(third program)
subplot(2,2,1)
plot(x,S)
subplot(2,2,2)
plot(x,E)
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
hold off
And i want to choose two legends.
The first legend is subplot(2,2,2) from the first program.
The second legend is subplot(2,2,2) from the third program.
How can i do this? Please help.

답변 (1개)

Ruger28
Ruger28 2019년 12월 18일
Just add the legend line in each "program".
(first program)
subplot(2,2,1)
plot(x,S)
hold on
subplot(2,2,2)
plot(x,E)
legend; % add legend to this subplot
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
(second program)
subplot(2,2,1)
plot(x,S)
subplot(2,2,2)
plot(x,E)
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
(third program)
subplot(2,2,1)
plot(x,S)
subplot(2,2,2)
plot(x,E)
legend; % add legend to this subplot
subplot(2,2,3)
plot(x,I)
subplot(2,2,4)
plot(x,R)
hold off
  댓글 수: 3
Fahmy Shandy
Fahmy Shandy 2019년 12월 18일
What i mean "program" in my question is about i have three different case in one script.
I have X as an initial value and then i plot it in the first subplot, then the second program is Y, continuing the X, the second program will plotting to continue the X, and the last one is Z. It's continuing from Y. So in short, as i said before, i have 4 subplot and each subplot has 3 overlapping graphs.
Btw, sorry for my english, but anyway i know you can understand what i mean here.
Fahmy Shandy
Fahmy Shandy 2019년 12월 18일
편집: Fahmy Shandy 2019년 12월 18일
Here is my problem
The legend "pj" must be blue, because i insert legend in the third program. But i don't know how this can be happen. Red color is from the first program that i've mentioned about

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

카테고리

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

태그

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by