2011-02-28 28 views
190

Matplotlib'de dağılım grafiği çizmeye çalışıyorum ve bu noktalara etiket ekleyemedim. Örneğin:Bir dağılım grafiği için tek tek etiketler nasıl eklenir

scatter1=plt.scatter(data1["x"], data1["y"], marker="o", 
        c="blue", 
        facecolors="white", 
        edgecolors="blue") 

I vb "nokta 1", "nokta" 2 gibi etiketler için "y" noktalar için tercih bunu anlamaya olabilir.

cevap

330

Belki plt.annotate kullanın: Ben diyecektim ne

import numpy as np 
import matplotlib.pyplot as plt 

N = 10 
data = np.random.random((N, 4)) 
labels = ['point{0}'.format(i) for i in range(N)] 

plt.subplots_adjust(bottom = 0.1) 
plt.scatter(
    data[:, 0], data[:, 1], marker='o', c=data[:, 2], s=data[:, 3] * 1500, 
    cmap=plt.get_cmap('Spectral')) 

for label, x, y in zip(labels, data[:, 0], data[:, 1]): 
    plt.annotate(
     label, 
     xy=(x, y), xytext=(-20, 20), 
     textcoords='offset points', ha='right', va='bottom', 
     bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5), 
     arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0')) 

plt.show() 

enter image description here

+7

. Dokümanlara bağlantı: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.annotate Demoya bağlantı: http://matplotlib.sourceforge.net/examples/pylab_examples/annotation_demo2.html – Paul

+0

Çok güzel! Bir çekicilik gibi çalıştı. –

+3

@ubuntu Puanların (veya etiketlerin) _instead_ kullanılması mümkün mü? – Vladtn

İlgili konular