import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.use('TkAgg') # 定义三个二维数组 xy1 = np.array([[40,0.0364],[50,0.0351],[60,0.0361],[70,0.0356],[80,0.0361]]) xy2 = np.array([[70,0.0356],[80,0.0361],[90,0.0356],[100,0.0358],[110,0.0359]]) xy3 = np.array([[100,0.0358],[110,0.0359],[120,0.0366],[130,0.0351]]) # 画出三条曲线 plt.plot(xy1[:,0], xy1[:,1], '-o', markersize=8, linewidth=2, label='curve 1') plt.plot(xy2[:,0], xy2[:,1], '-o', markersize=8, linewidth=2, label='curve 2') plt.plot(xy3[:,0], xy3[:,1], '-o', markersize=8, linewidth=2, label='curve 3') # 添加标签和图例 plt.xlabel('x') plt.ylabel('y') plt.legend() plt.show(),这个代码,我需要将三条曲线注明一下每条曲线代表啥,我该添加什么代码
时间: 2023-07-02 19:12:09 浏览: 156
您可以在画每条曲线的时候,通过label参数来为每条曲线添加名称,然后在图例中显示出来。修改后的代码如下所示:
```python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('TkAgg')
# 定义三个二维数组
xy1 = np.array([[40,0.0364],[50,0.0351],[60,0.0361],[70,0.0356],[80,0.0361]])
xy2 = np.array([[70,0.0356],[80,0.0361],[90,0.0356],[100,0.0358],[110,0.0359]])
xy3 = np.array([[100,0.0358],[110,0.0359],[120,0.0366],[130,0.0351]])
# 画出三条曲线,添加标签
plt.plot(xy1[:,0], xy1[:,1], '-o', markersize=8, linewidth=2, label='curve 1')
plt.plot(xy2[:,0], xy2[:,1], '-o', markersize=8, linewidth=2, label='curve 2')
plt.plot(xy3[:,0], xy3[:,1], '-o', markersize=8, linewidth=2, label='curve 3')
# 添加标签和图例
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
```
您可以根据需要将label参数修改为对应的名称。
阅读全文