How to exclude some additional points from plot legend?
25 次查看(过去 30 天)
显示 更早的评论
The code generates plots in a loop and legend is given by an array contianing names. I am adding multiple single points at the end. How can I exclude these points from legend? I tried adding these points after addition of legened but legened showed points as well.
0 个评论
回答(2 个)
Shubham Gupta
2019-10-28
You can assign plot to different variables and when you use legend only use handles of the assigned variables. For e.g.
figure(1);
hold on;
l1 = plot(1:10);
l2 = plot(2:2:20);
l3 = plot(3:3:30);
Now, if you want legend only for l1 & l3 to show up. You can use:
legend([l1,l3],'Line-1','Line-3') % This will show legend for l1 & l3 only
I hope it helps !
0 个评论
ME
2019-10-28
An alternative to the answer of Shubham Gupta if you already have the figure plotted and you want to keep all of the points but simply remove some from the legend. If you select all of the items you want removed from the legend, go to "view>property editor" then click on "More Properties...". This will open a popout in which you can look for the "Handle Visibility" category - change this to "off" and the selected items will disappear from you legend.
You can also re-select them, go back to this menu and turn Handle Visibility back on if you later decide you want those items in your legend.
1 个评论
Kristin Schall - van Bellen
2020-8-19
If the "Handle Visibility" category has the Value "on", is there a way to delet the points for the UIAxes?
I got the same problem as Zeynab but I don' know the exact number of lines that will be seen in the UIAxes an the legend, so the first answere is no option to me.
app.UIAxes.HandleVisibility='on' and cla(app.UIAxes) is not working...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!