I have a numpy array and i'm trying to plot it with a scatter plot using matplotlib.
from matplotlib import pyplot as plt
from matplotlib import pylab as pl
pl.plot(matrix[:,0],matrix[:,1], 'ro')
This gives me something like :
Now i want to replace the red dots by a number correspondig to the index of the row in the numpy array. How could i do it ?
Thank you !
You can do this using 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()
If you want to replace the red dots, then set alpha = 0.0
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With