How to exclude some additional points from plot legend?

17 vues (au cours des 30 derniers jours)
Zeynab Mousavikhamene
Zeynab Mousavikhamene le 27 Oct 2019
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.

Réponses (2)

Shubham Gupta
Shubham Gupta le 28 Oct 2019
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 !

ME
ME le 28 Oct 2019
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 commentaire
Kristin Schall - van Bellen
Kristin Schall - van Bellen le 19 Août 2020
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...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by