Showing a legend for a "group" of plots
63 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/597335/image.png)
Thanks
0 Commenti
Risposta accettata
Walter Roberson
il 26 Apr 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!