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

发布于:2022-12-05 ⋅ 阅读:(407) ⋅ 点赞:(0)

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')

在这里插入图片描述

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到