2012-12-18 12 views
5

Voglio tracciare frecce con matplotlib in modo che ogni punta di freccia abbia le stesse dimensioni, indipendentemente dalla dimensione della freccia effettiva.Frecce di dimensioni uguali in formato matricola

Esempi:

Le frecce sono disegnate usando 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

si può mostrare il codice in cui si sta effettivamente disegnare le frecce? – mgilson

risposta

5

Stai cercando pylab.arrow (o FancyArrow), quindi è possibile specificare head_width e head_length in modo che non siano relativi alla dimensione della freccia. Ecco un esempio:

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() 

che produce:

enter image description here

+0

Questo è un bell'esempio! –

Problemi correlati