Matlab plot多条曲线使用legend标注某几条图例

 时间:2026-02-15 15:34:52

1、首先,我们创建六条曲线,分两次绘制曲线

x = 0 : 0.01 : 4*pi;

y1 = sin(x);

y2 = cos(x);

y3 = 3*cos(x);

y4 = cos(x).*sin(x);

y5 = cos(x) + sin(x);

y6 = cos(x) - 2*sin(x);

h1 = plot(x,y1,x,y2,x,y3);

hold on 

h2 = plot(x,y4,x,y5,x,y6);

Matlab plot多条曲线使用legend标注某几条图例

2、画出来的图像如图所示。

Matlab plot多条曲线使用legend标注某几条图例

3、接下来我们添加图例

legend('sin(x)','cos(x)','3cos(x)','cos(x)*sin(x)','cos(x) + sin(x)','cos(x) - sin(x)')

观察每条曲线的颜色,如图

Matlab plot多条曲线使用legend标注某几条图例

4、然后我们选择曲线1,曲线3,曲线5添加图例

legend([h1(1),h1(3),h2(2)],'sin(x)','3cos(x)','cos(x) + sin(x)')

更改曲线1,曲线3,曲线5的显示方式,如图

Matlab plot多条曲线使用legend标注某几条图例

5、运行程序,观察结果

Matlab plot多条曲线使用legend标注某几条图例

6、注意我们画图时要记录句柄值,例子中的h1,h2

  • matlab怎样将两张图放到一张图上
  • matlab如何画直线
  • MATLAb怎样设置坐标轴
  • 如何在matlab画的图中改变坐标显示的范围
  • matlab设置坐标轴范围
  • 热门搜索
    浙江旅游攻略 梵净山旅游 桂林旅游股票 石家庄周边旅游景点 沈阳旅游景点 奖励旅游 信阳旅游 旅游市场营销 尼泊尔旅游 沈阳旅游攻略