How can we adjust the line width and color in MATLAB?
In MATLAB, you can use the LineWidth attribute to set the width of a line and the Color attribute to set the color of the line.
Here is a sample code showing how to set the line width and 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)');
The above code will plot the curves of sin(x) and cos(x), with sin(x) having a line width of 2 and being colored red, while cos(x) will have a line width of 1 and be colored blue.