How to exclude some additional points from plot legend?

조회 수: 27 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 10월 27일
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.

답변 (2개)

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

ME
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
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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by