legend for selected plot objects in MATLAB figure

后端 未结 1 750
臣服心动
臣服心动 2021-01-15 04:38

For a MATLAB figure, I have something like:

figure; hold on;
line ( [1 2], [3 4] );
line ( [5 6], [7 8] );

plot(x1,y1,\'r.\');
plot(x2,y2,\'b.\');


        
相关标签:
1条回答
  • 2021-01-15 05:36

    You will have to get the handles for the last two plots and tell legend to plot only for those two. For example:

    h1 = plot(x1,y1,'r.');
    h2 = plot(x2,y2,'b.');
    legend([h1,h2],'red','blue')
    
    0 讨论(0)
提交回复
热议问题