Showing a legend for a "group" of plots
81 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am plotting 3 vectors (x1,x2,x3 - each has about 5 values) as lines
plot([x1 x1],[0 1],'r.-');hold on
plot([x2 x2],[0 2],'Color','blue','LineStyle','--','LineWidth',2)
plot([x3 x3],[0 2],'Color','green','LineStyle','--','LineWidth',2)
grid on; xlabel('Time(ms)');
I want to add just 3 legends for each colour. However, when I do this, it adds the 3 legends for the first 3 plots (i.e. red lines).
legend('Camera','Extreme1','Extreme2',"Location",'best','FontSize',12);
How do I show the legend just once for each colour?
Thanks
0 commentaires
Réponse acceptée
Walter Roberson
le 26 Avr 2021
h1 = plot([x1 x1],[0 1],'r.-');hold on
h2 = plot([x2 x2],[0 2],'Color','blue','LineStyle','--','LineWidth',2)
h3 = plot([x3 x3],[0 2],'Color','green','LineStyle','--','LineWidth',2)
grid on; xlabel('Time(ms)');
legend( [h1(1), h2(1), h3(1)], {'Camera','Extreme1','Extreme2'},"Location",'best','FontSize',12);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!