温馨提示×

matlab怎么设置线宽和颜色

小亿
218
2024-02-04 09:32:43
栏目: 编程语言

在MATLAB中,可以使用LineWidth属性来设置线宽,使用Color属性来设置线的颜色。

下面是一个示例代码,演示如何设置线宽和颜色:

x = linspace(0, 2*pi, 100);
y1 = sin(x);
y2 = cos(x);

% 创建一个新的图形窗口
figure;

% 绘制sin(x)的曲线,线宽为2,颜色为红色
plot(x, y1, 'LineWidth', 2, 'Color', 'red');
hold on; % 在同一图形窗口上继续绘制其他曲线

% 绘制cos(x)的曲线,线宽为1,颜色为蓝色
plot(x, y2, 'LineWidth', 1, 'Color', 'blue');

% 设置坐标轴的标签和标题
xlabel('x');
ylabel('y');
title('Plot of sin(x) and cos(x)');

% 添加图例
legend('sin(x)', 'cos(x)');

上述代码会绘制出sin(x)和cos(x)的曲线,其中sin(x)的线宽为2,颜色为红色;cos(x)的线宽为1,颜色为蓝色。

0