1 importmatplotlib.pyplot as plt2 defdrawArrow(A,B):3 fig =plt.figure()4 ax = fig.add_subplot(111)5 """

6 箭头起始位置(A[0],A[1])和终点位置(B[0],B[1])7 length_includes_head = True:表示增加的长度包含箭头部分8 head_width:箭头的宽度9 head_length:箭头的长度10 fc:filling color(箭头填充的颜色)11 ec:edge color(边框颜色)12 """

13 ax.arrow(A[0],A[1],B[0]-A[0],B[1]-A[1],length_includes_head = True,head_width = 0.25,head_length = 0.5,fc = 'r',ec = 'b')14 ax.set_xlim(0,10) #设置图形的范围,默认为[0,1]

15 ax.set_ylim(0,10) #设置图形的范围,默认为[0,1]

16 ax.grid() #添加网格17 ax.set_aspect('equal') #x轴和y轴等比例

18 plt.show()19 plt.tight_layout()20

21 A = [1,2,3,4,5,6,7]22 B = [3,4,5,6,7,8,9]23 drawArrow(A,B)