2016-12-27 863 views
4

我想標記python中的每一個點,我沒有找到正確的方法來完成它。在Python中執行散點圖時標記數據

假設我有一個名爲abn元素的兩個列表,我打印出來是這樣的:

plt.figure() 
    plt.grid() 
    plt.plot(a , b , 'bo') 
    plt.show() 

我要標註爲「變量k」與k1n顯然每一個點。 感謝您的時間

+1

可能的重複[如何在Matplotlib中設置圖形標題和軸標籤字體大小?](http://stackoverflow.com/questions/12444716/how-do-i-set-the-figure-title-and- axis-labels-font-size-in-matplotlib) –

+0

^^這是設置軸的名稱'。我相信他想標註每一個點。 –

+0

你試過了什麼?請***請讀*** [問]和[mcve]。堆棧溢出具有非常高的質量標準。 –

回答

0

這裏是我發現這樣做的最好辦法:

plt.figure() 
plt.scatter(a,b) 
labels = ['Variable {0}'.format(i+1) for i in range(n)] 
for i in range (0,n): 
    xy=(a[i],b[i]) 
    plt.annotate(labels[i],xy) 
plt.plot() 

更多的相關信息:Matplotlib: How to put individual tags for a scatter plot

0

可以使用label情節參數

x = np.random.random(3) 
y = np.random.random(3) 
z = np.arange(3) 
colors = ["red", "yellow", "blue"] 
c = ["ro", "yo", "bo"] 

for i in z: 
    plt.plot(x[i], y[i], c[i], label=colors[i] + ' ' + str(i)) 
plt.legend() 

enter image description here

相關問題