import scipy.spatial as spt import numpy as np import matplotlib.pyplot as plt plt.rc('font', family='simhei', Size =10) # Set Chinese display, Plt.rc ('axes', Unicode_minus =False) # Points = np.random. RandInt (1,20,(10,2)) # Scatter (x=points[:, 0], y=points[:, 1], s=150,color='red', Scatter (x=points[:, 0], y=points[:, 1], s=150,color='red', Marker ='o') # mark all sample points S represents the size of marker. Note that the first two parameters are not coordinate points. Tree = spt.ckdtree (data=points) for point in points: int (); int (); int (); int (); int (); Accommodate, indexs = tree.query(point, k=2) # point refers to current point, point[0] = x coordinate of current point, # points[indexs[1]] # points[indexs[1]] # points[indexs[1]] # points[indexs[1]] # points[indexs[1]] # points[indexs[1]] # points[indexs[1]] Points [indexs [1]] and [0] points [indexs [1]], [1] represents the point of x and y coordinates x = [point [0], points [indexs [1]] [0]] y = [point [1]. Points [indexs[1]][1]] # plt.plot(x,y, color='black') # plt.plot(x,y, color='black') # plt.plot(x,y, color='black') Arrow (x=point [0],y= point[1], dx=points[indexs[1]][0]-point[0], Dy =points[indexs[1]][1]-point[1],width=0.1,length_includes_head=True, color='green') https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.arrow.html PLT. Text (sum (x) / 2, the sum (y) / 2, fontsize = 10, Since x is a set of x coordinates of two points, sum(x)/2 represents the center of the line, and write in the middle (s represents the string to be written) plt.show() # to show the image