2012-12-18 75 views
5

我想用matplotlib繪製箭頭,以便每個箭頭的大小相同,而不管實際的箭頭大小。matplotlib中的等號箭頭

實例:

箭頭使用matplotlib.pyplot.Arrow繪製():

# p is the point of origin, pdiff the direction   
arr = plt.Arrow(p[0], p[1], pdiff[0], pdiff[1], fc=color, width=0.4) 
plt.gca().add_patch(arr) 
+2

你能告訴你在哪裏實際繪製箭頭的代碼? – mgilson

回答

5

你是在pylab.arrow(或FancyArrow),那麼您可以指定head_widthhead_length,以便它們與箭頭的大小無關。這裏有一個例子:

import math 
import pylab 

pylab.plot(range(11), range(11)) 

opt = {'head_width': 0.4, 'head_length': 0.4, 'width': 0.2, 
     'length_includes_head': True} 
for i in xrange(1, 360, 20): 
    x = math.radians(i)*math.cos(math.radians(i)) 
    y = math.radians(i)*math.sin(math.radians(i)) 

    # Here is your method.  
    arr = pylab.Arrow(4, 6, x, y, fc='r', alpha=0.3) 
    pylab.gca().add_patch(arr) 

    # Here is the proposed method. 
    pylab.arrow(4, 6, x, y, alpha=0.8, **opt) 

pylab.show() 

主要生產:

enter image description here

+0

這是一個很好的例子! –