matplotlib绘制6条折线图指定折线的颜色
时间: 2023-12-10 08:24:17 浏览: 26
要在matplotlib中绘制6条折线图并指定每条折线的颜色,您可以使用`plot`函数的`color`参数来指定颜色。下面是一个示例代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 生成一些示例数据
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)
y4 = np.exp(-x)
y5 = np.log(x + 1)
y6 = np.sqrt(x)
# 绘制折线图并指定颜色
plt.plot(x, y1, color='red', label='Line 1')
plt.plot(x, y2, color='green', label='Line 2')
plt.plot(x, y3, color='blue', label='Line 3')
plt.plot(x, y4, color='purple', label='Line 4')
plt.plot(x, y5, color='orange', label='Line 5')
plt.plot(x, y6, color='brown', label='Line 6')
# 添加图例和标签
plt.legend()
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# 显示图形
plt.show()
```
在这个例子中,我们使用了不同的颜色来绘制6条折线图。您可以根据需要修改颜色名称或使用其他可接受的颜色表示方式,例如RGB值。