MATLAB中忽略特定图例

在MATLAB画图中,有时需要忽略某些legend,有几种方法可以实现:

  1. 在画不需要图例的线条时添加'HandleVisibility','off'
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1);

hold on
y2 = cos(2*x);
plot(x,y2,'HandleVisibility','off');

y3 = cos(3*x);
plot(x,y3);
hold off
legend('First','Third')
  1. legend函数中添加subset,例如
x = linspace(0,pi);
y1 = cos(x);
p1 = plot(x,y1);

hold on
y2 = cos(2*x);
p2 = plot(x,y2);

y3 = cos(3*x);
p3 = plot(x,y3);
hold off

legend([p1 p3],{'First','Third'})

两者效果相同
MATLAB中忽略特定图例_第1张图片

你可能感兴趣的:(MATLAB)