MATLAB plot 函数

x 创建为由 0 和 2π 之间的线性间隔值组成的向量。在各值之间使用递增量 π/100。将 y 创建为 x 的正弦值。创建数据的线图。

x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)

使用legend命令添加图例,具体调用格式如下图所示。

MATLAB plot 函数

MATLAB plot 函数

% 利用legend函数的参数进行大致设置
legend('sinx',-1); % 位于图形框外面
legend('sinx',0); % 最佳位置
legend('sinx',1); % 右上角
legend('sinx',2); % 左上角  MATLAB plot 函数
legend('sinx',3); % 左下角
legend('sinx',4); % 右下角

 

 

原文链接  https://ww2.mathworks.cn/help/matlab/ref/plot.html#d117e995789