Does anyone know how to add the legend?
Show older comments
Hello everyone,
I know it's not that complicated, but I 've never added a legend.
Can anyone help me,please?
I need to put in legend the red and blue points, the green, magenta and cyan lines.
Thank you!
2 Comments
John D'Errico
on 23 Jul 2021
Edited: John D'Errico
on 23 Jul 2021
WILL YOU PLEASE STOP SHOUTING?
All caps are considered shouting online, and it tends to be thought of as rude. I would note that you have started posting your questions in all caps, though you did not do so at first. Please stop it.
And, does anyone know how to add a legend? Yes. I do.
Pul
on 23 Jul 2021
Accepted Answer
More Answers (1)
x = rand(1,5);
y1 = x + 2;
y2 = x*2;
plot(x,y1,'ro')
hold on
plot(x,y2,'bs')
legend('+2','*2')
Really, pretty basic. In fact, you would find all this in the help for legend.
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!


