使用注解工具:ax.annotate
参数说明:
Axes.annotate(s, xy, *args, **kwargs)
s:注释文本的内容xy:被注释的坐标点,二维元组形如(x,y)xytext:注释文本的坐标点,也是二维元组,默认与xy相同xycoords:被注释点的坐标系属性,允许输入的值如下
示例:
import numpy as np
import matplotlib.pyplot as plt
point_num = 10
point=np.random.random((point_num, 2))
n=np.arange(point_num)
fig,ax=plt.subplots()
ax.scatter(point[:, 0], point[:, 1],c='r')
for i,txt in enumerate(n):
ax.annotate(txt,(point[i][0], point[i][1]))
plt.show()