如何在matplotlib(python)中标记一行?

Sib*_*ing 13 python matplotlib

我按照文档,但仍然没有标记一行.

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
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,我试图绘制出北方向和东方向.

position 包含要绘制的点.

但我最终得到两条没有标签的直线,如下所示: 在此输入图像描述

出了什么问题?

sha*_*kde 19

该参数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()
Run Code Online (Sandbox Code Playgroud)

这将绘制2条线,如图所示: 情节有2条线

箭头功能支持标签.请检查此链接:http: //matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.arrow