2017-03-02 40 views
2

我有一個numpy數組,我試圖用散佈圖使用matplotlib繪製它。Matplotlib以numpy行索引作爲標記的散點圖

from matplotlib import pyplot as plt 
from matplotlib import pylab as pl 

pl.plot(matrix[:,0],matrix[:,1], 'ro') 

這給了我這樣的: plot

現在我想通過一些correspondig到行的numpy的數組中的索引來代替紅點。我怎麼能這樣做?

謝謝!

回答

3

可以使用plt.text做到這一點:

from matplotlib import pyplot as plt 

import numpy as np 
N = 100 
matrix = np.random.rand(N,2) 

plt.plot(matrix[:,0],matrix[:,1], 'ro', alpha = 0.5) 
for i in range(matrix.shape[0]): 
    plt.text(matrix[i,0], matrix[i,1], str(i)) 

plt.show() 

enter image description here

如果你想更換紅點,然後設置alpha = 0.0

enter image description here

+0

哦,我沒」不要想那個!非常感謝你 – clechristophe