Matlab多条曲线标注某几条曲线的图例 (legend函数)

1、绘制多条曲线

x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
y4 =sin(x-0.75);
y5 = sin(x-1);
y6 = sin(x-1.25);
y7 = sin(x-1.5);
y8 =sin(x-1.75);
figure
plot(x,y1,'y');hold on;
plot(x,y2,'m');hold on;
plot(x,y3,'c');hold on;
plot(x,y4,'r');hold on;
plot(x,y5,'g');hold on;
plot(x,y6,'b');hold on;
plot(x,y7,'k');hold on;
plot(x,y8,'k');hold on;

2、给其中几条曲线添加图例

x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
y4 =sin(x-0.75);
y5 = sin(x-1);
y6 = sin(x-1.25);
y7 = sin(x-1.5);
y8 =sin(x-1.75);
figure
plot(x,y1,'y');hold on;
plot(x,y2,'m');hold on;
h1=plot(x,y3,'c');hold on;
plot(x,y4,'r');hold on;
h2=plot(x,y5,'g');hold on;
plot(x,y6,'b');hold on;
h3=plot(x,y7,'k');hold on;
plot(x,y8,'k');hold on;
legend([h1,h2,h3],'曲线1','曲线2','曲线3')

你可能感兴趣的:(Matlab,matlab,算法,python)