import matplotlib.pyplot as plt
def drawArrow(A,B):
fig = plt.figure()
ax = fig.add_subplot(111)
"""
箭頭起始位置(A[0],A[1])和終點位置(B[0],B[1])
length_includes_head = True:表示增加的長度包含箭頭部分
head_width:箭頭的寬度
head_length:箭頭的長度
fc:filling color(箭頭填充的顏色)
ec:edge color(邊框顏色)
"""
ax.arrow(A[0],A[1],B[0]-A[0],B[1]-A[1],length_includes_head = True,head_width = 0.5,width=0.25,head_length = 0.5,fc = 'r',ec = 'r')
ax.plot(3, 3,color='k',alpha=1,marker='o',markersize='1') #,markersize='1'
ax.set_xlim(0,10) #設置圖形的范圍,默認為[0,1]
ax.set_ylim(0,10) #設置圖形的范圍,默認為[0,1]
ax.grid() #添加網格
ax.set_aspect('equal') #x軸和y軸等比例
plt.show()
plt.tight_layout()
# A = [1,2,3,4,5,6,7]
# B = [3,4,5,6,7,8,9]
A=[3,1]
B=[3,4]
drawArrow(A,B)
另外一種 利用 annotate 也可以 打標簽和畫箭頭
ax.annotate('', xy=(lon_max[i], lat_max[i]+0.08), xytext=(lon_max[i]-0.001, lat_max[i]), arrowprops=dict(arrowstyle="->", color="r", hatch='*'))