Python中繪制箭頭


以兩個點為例,其中起點為點(1,2),終點為點(3,4)

 1 import matplotlib.pyplot as plt
 2 def drawArrow(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)

輸出情況:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM