MATLAB Answers

How to exclude some additional points from plot legend?

48 views (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 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.

  0 Comments

Sign in to comment.

Answers (2)

Shubham Gupta
Shubham Gupta on 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 !

  0 Comments

Sign in to comment.


ME
ME on 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 Comment

Kristin Schall - van Bellen
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...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!