2016-12-22 40 views
0

我想添加標籤由matplotlib自動生成點的熊貓數據框對象添加標籤點,但我不知道如何從我的熊貓找到點(boldened i及以下j) DataFrameGroupby對象。我的命令來創建一個圖是使用Matplotlib

for x, group in graph: 
    t = group.plot(x="CompressorSpeed", y="ratio", marker='o').set_title(x) 
    plt.annotate('This is awesome', xy=(**i**, **j**), arrowprops=dict(arrowstyle="->")) 
    plt.savefig(pp, format="pdf") 

凡圖是(和csvdata是從read_csv(...)創建熊貓數據框對象)

graph=csvdata.groupby("CompressorAlgo", as_index=False) 

我可以驗證一個xy標籤如果創建的話我硬編碼一個已知點。

這裏是一個標誌點一份附圖片:

enter image description here

+0

點是數據框中的數據。你想標記每個數據點嗎?請參閱http://matplotlib.org/devdocs/users/annotations.html – tacaswell

+0

只要我們不知道您想用哪種標準來標記您的觀點,我擔心我們無法幫助您。 – ImportanceOfBeingErnest

+0

我指的是圖中創建的'marker'點。我附上了一張照片('marker'點是較大的圓點)。 – BlazePascal

回答

1

它真的很難確定,因爲你不提供你的數據框的內容。在未來,請考慮生成Minimal, Complete, and Verifiable example

話雖這麼說,我認爲這是你在找什麼:

for x, group in graph: 
    t = group.plot(x="CompressorSpeed", y="ratio", marker='o').set_title(x) 
    for i,j in group[["CompressorSpeed","ratio"]].values: 
     plt.annotate('This is awesome', xy=(i,j), arrowprops=dict(arrowstyle="->")) 
    plt.savefig(pp, format="pdf") 

實現同樣的事情的另一種方式,但它可能是更容易閱讀將是:

for z,row in group.iterrows(): 
      plt.annotate('This is awesome', xy=(row["CompressorSpeed"],row["ratio"]), arrowprops=dict(arrowstyle="->"))