Plot - add legend individually
82 views (last 30 days)
Show older comments
How can I update the legend of each plot individually rather than at the end of the code ?
plot(x1, y1,'-vr','LineWidth', linewidth,“标记”, markersize);
legend('Algorithm 1');
plot(x2, y2,'-vr','LineWidth', linewidth,“标记”, markersize);
legend('Algorithm 2');
The code above overwrites the legend for Algorithm 1
1 Comment
ROBIN KUMAR
on 18 Feb 2022
The same problem I have been facing with R2021a version. Please help me execute the same..
Accepted Answer
亚当
2017年7月13日
Edited:亚当
2017年7月13日
If you are working with a fairly recent version of Matlab (> R2014b I think) then you can edit an existing legend if you keep the handle to it:
figure; hAxes = gca;
plot(hAxes, x1, y1,'-vr','LineWidth', linewidth,“标记”, markersize);
hLegend =传奇(hax,'stuff');
hold( hAxes,'on')
情节(haxes,x2,y2,'-vr','LineWidth', linewidth,“标记”, markersize);
hLegend.String{2} ='other stuff';
It is more efficient to do all the plots first and then put the legend up for all of them though.
3 Comments
ROBIN KUMAR
on 18 Feb 2022
This doesn't work at all. The same problem I have been facing with R2021a version. Please help me execute the same..
More Answers (1)
ROBIN KUMAR
on 18 Feb 2022
The same problem I have been facing with R2021a version. Please help me execute the same..