我按照文档进行操作但仍无法标记一行。
plt.plot([min(np.array(positions)[:,0]), max(np.array(positions)[:,0])], [0,0], color='k', label='East') # West-East
plt.plot([0,0], [min(np.array(positions)[:,1]), max(np.array(positions)[:,1])], color='k', label='North') # South-North
在上面的代码片段中,我试图绘制出北方向和东方向。
position
包含要绘制的点。
但我最终选择了两条没有标签的直线,如下所示:
出了什么问题?
答案 0 :(得分:13)
参数label
用于设置将在图例中显示的刺痛。例如,请考虑以下代码段:
import matplotlib.pyplot as plt
plt.plot([1,2,3],'r-',label='Sample Label Red')
plt.plot([0.5,2,3.5],'b-',label='Sample Label Blue')
plt.legend()
plt.show()
这将绘制2条线,如图所示:
箭头功能支持标签。请检查此链接: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.arrow
答案 1 :(得分:1)