2013-07-30 109 views
8

我跟着文檔,但仍未能標出一行。如何在matplotlib(python)中標記一行?

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包含要繪製的點。

但我結束了2條直線,沒有標籤如下: enter image description here

哪裏出了問題?

+3

據我所知標籤參數是爲圖例。你可能想看看這個註釋:http://matplotlib.org/users/annotations_intro.html - 放入一個plt.legend(),你會看到標籤打開。 – shaunakde

回答

8

參數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行如下所示: Plot With 2 lines

箭頭功能支持標籤。請檢查此鏈接: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.arrow

相關問題