MATLAB Answers

Changing order of legend entries

2 views (last 30 days)
Christian Schwermer
Christian Schwermer on 20 Nov 2020
Commented: Ameer Hamza on 22 Nov 2020
Hi guys,
does anybody know, how to change the order of entries in the legend? Changing the order of the plots is not possible, because the black dashed lines have to be on top.
Thanks!
Christian

Answers (1)

Ameer Hamza
Ameer Hamza on 20 Nov 2020
Edited: Ameer Hamza on 20 Nov 2020
You can change the order, but for that you need the handle for each line. For example, plot two lines
p1 = plot(rand(1,10));
p2 = plot(rand(1,10));
Now you can use these handles to set the order of legends
legend([p2 p1], {'P2', 'P1'})
%^ this order decide how it will appear in legend

Community Treasure Hunt

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

Start Hunting!