How to select legend in multiple subplot?

3 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by