【发布时间】:2019-12-12 02:23:25
【问题描述】:
自 MATLAB R2017a 起,在向坐标区添加绘图时,图形图例会自动更新。以前,可以这样做:
data = randn(100,4);
plot(data)
legend('line1','line2','line3','line4')
hold on
plot([1,100],[0,0],'k-')
用图例绘制四条数据线,然后为 y=0 添加一条黑线。但是,从 R2017a 开始,这会导致将黑线添加到图例中,名称为“data1”。
如何防止将这一行添加到图例中,以使代码的行为与旧版本 MATLAB 中的行为一样?
到目前为止,我在 Stack Overflow 上找到的唯一解决方案是 remove the legend item after it has been added。语法不漂亮:
h = plot([1,100],[0,0],'k-'); % keep a handle to the added line
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
【问题讨论】:
标签: matlab plot matlab-figure legend