Showing a legend for a "group" of plots
86 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2021 年 4 月 26 日
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);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!