Effacer les filtres
Effacer les filtres

How to have two legends on the same plot?

301 vues (au cours des 30 derniers jours)
Miguel Martinez
Miguel Martinez le 23 Fév 2023
Réponse apportée : Askic V le 23 Fév 2023
I just want to see a basic example of how to put two legends on the same plot on MATLAB 2020 and beyond...

Réponses (2)

Askic V
Askic V le 23 Fév 2023
Perhaps you meant this:
t = 0:0.1:5;
y = sin(t);
z = cos(t);
figure; hold on;
for i = 1:2
p1(i) = plot(t, y,'r');
p2(i) = plot(t, z,'b');
end
hold off
legend([p1(1) p2(1)],'sin', 'cos');
ah1 = axes('position',get(gca,'position'),'visible','off');
legend(ah1, [p1(2) p2(2)], {'Test1','Test2'}, 'Location','SouthWest');

KSSV
KSSV le 23 Fév 2023
figure
hold on
plot(rand(1,10),'r')
plot(rand(1,10),'b')
legend('One','Two')

Community Treasure Hunt

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

Start Hunting!

Translated by