Showing a legend for a "group" of plots

61 次查看(过去 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

采纳的回答

Walter Roberson
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 CenterFile Exchange 中查找有关 Legend 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by