Remove an item in legend

21 次查看(过去 30 天)
Lizan
Lizan 2013-5-7
回答: Laura F 2022-5-6
Hi,
I have a legend like
x, y, spline
I would like the legend to only show x, y and not show spline as a dataset. How can I do this? I would preferably not have to redo the whole image.

回答(2 个)

Sean de Wolski
Sean de Wolski 2013-5-7
How abotu just calling legend again without the input for the line you don't want:
hLine = plot(1:10,1:10,'r-',1:10,10:-1:1,'b-');
hLegend = legend(hLine,'up','down');
Now to remove it:
%Add another legend:
legend(hLine(1),'up')
  2 个评论
Lizan
Lizan 2013-5-7
My problem is that this new entry is not one I plot. It comes from the fitting tool that I added directly in the figure. But I don't want it to show as a separate label.
There is no way to manually fetch the name of the handle and then turn it off or remove it manually?
Sean de Wolski
Sean de Wolski 2013-5-7
There might be a way to do this by removing children from the Legend and from shortening the string property:
get(hLegend)
Then use set() to change the ones you need.

请先登录,再进行评论。


Laura F
Laura F 2022-5-6
I hope, that I understand the question right. I had the same problem and solved it like this:
Lgnd = legend('show','Orientation','horizontal');
Lgndstr = Lgnd.String(1:2);
Lgnd.String = Lgndstr;

类别

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