使用
matplotlib.arrow()函数,将head_length和head_width参数设置为0,以避免出现“箭头结束”。不同点之间的连接可以通过向量加法简单计算得出:
A = [1,2], B=[3,4] --> A到B的连接是B-A = [2,2]。
从A的尖端开始绘制该向量,最终到达B的尖端。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use('fivethirtyeight')
A = np.array([[10,8],[1,2],[7,5],[3,5],[7,6],[8,7],[9,9],[4,5],[6,5],[6,8]])
fig = plt.figure(figsize=(10,10))
ax0 = fig.add_subplot(212)
ax0.scatter(A[:,0],A[:,1])
ax0.arrow(A[0][0],A[0][1],A[1][0]-A[0][0],A[1][1]-A[0][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
ax0.arrow(A[2][0],A[2][1],A[9][0]-A[2][0],A[9][1]-A[2][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
ax0.arrow(A[4][0],A[4][1],A[6][0]-A[4][0],A[6][1]-A[4][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
plt.show()
![enter image description here](https://istack.dev59.com/qNPtA.webp)