I want to plot arrows with matplotlib so that every arrowhead is of equal size, regardless of of the actual arrow's size.
Examples:
The arrows are drawn using 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)
You are after pylab.arrow
(or FancyArrow
), then you can specify head_width
and head_length
so they are not relative to the size of the arrow. Here is an example:
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()
Which produces:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With