How to select legend in multiple subplot?

2 visualizaciones (últimos 30 días)
Fahmy Shandy
Fahmy Shandy el 18 de Dic. de 2019
Editada: Fahmy Shandy el 18 de Dic. de 2019
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.

Respuestas (1)

Ruger28
Ruger28 el 18 de Dic. de 2019
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 comentarios
Fahmy Shandy
Fahmy Shandy el 18 de Dic. de 2019
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 el 18 de Dic. de 2019
Editada: Fahmy Shandy el 18 de Dic. de 2019
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

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by