How to select legend in multiple subplot?
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Ruger28
on 18 Dec 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 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!