SoFunction
Updated on 2024-12-15

How python matplotlib labels points in a plot

This article introduces the python matplotlib to the point in the map with labels, the text through the sample code is very detailed, for everyone's learning or work has a certain reference value of learning, the need for friends can refer to the next!

I was writing a paper using matplotlib to draw a scatterplot, and thought it would be nice to type the ID corresponding to each point next to the point, and after a bit of searching, I finally found a way to do it.

The first step is to hit the dots and draw all the dots first, as an example:

p1 = (X[:,0], X[:,1], marker = '*', color = 'r', label='1', s=10)

Then label each point in turn:

for i in range(0, len(X)):
    (X[i,0],X[i,1], i)

The final effect:

This is the whole content of this article.