How to select legend in multiple subplot?

2 次查看(过去 30 天)
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