可以通过执行h.HandleVisibility =‘off’或h.Annotation.LegendInformation.IconDisplayStyle =‘off’来抑制线对象h的图例条目。但是,这两个动作也阻止了曲线……
您还可以关闭手柄可见性。这比将每个图设置为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 function接受一个可选参数,列出要包含在图例中的句柄:
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.