MATLAB:抑制传奇条目,而无需从绘图浏览器中删除



可以通过执行h.HandleVisibility='off'h.Annotation.LegendInformation.IconDisplayStyle='off'来抑制行对象h的传奇条目。但是,这两个操作还可以防止曲线出现在MATLAB的绘图浏览器用户界面中,因此曲线的显示无法交互。

是否有任何方法可以抑制给定曲线的传奇条目,而无需删除在绘图浏览器用户界面中切换该曲线的能力?

您也可以关闭句柄可见度。这比必须将每个图设置为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')

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.

最新更新