matlab:在不从绘图浏览器中删除的情况下抑制图例条目

问题描述 投票:1回答:2

可以通过执行hh.HandleVisibility='off'来抑制线对象h.Annotation.LegendInformation.IconDisplayStyle='off'的图例条目。但是,这两个操作也会阻止曲线出现在Matlab的Plot Browser用户界面中,因此无法以交互方式切换曲线的显示。

有没有办法抑制给定曲线的图例条目而不删除在绘图浏览器用户界面中切换该曲线显示的功能?

matlab plot matlab-figure legend
2个回答
1
投票

MATLAB的legend函数接受一个可选参数,列出要包含在图例中的句柄:

figure, hold on
h1 = plot(1,1,'ro');
h2 = plot(1,2,'gx');
h3 = plot(2,1,'m*');
legend([h1,h3]);  % don't make a legend for h2.

0
投票

您还可以关闭手柄可见性。这比将每个图设置为h1 =更容易...

例:

x1 = randperm(10);
y = randperm(10);
x2 = randperm(10);

plot(x1, y, '-', 'Color', 'black', 'HandleVisibility', 'off')
hold on
plot(x2, y, '-', 'Color', 'green', 'DisplayName', 'Put This In Legend')
lgd = legend;
set(lgd, 'Location', 'best')
© www.soinside.com 2019 - 2024. All rights reserved.