2017-03-02 38 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