Reputation: 5579
I would like to hide the shaft of the arrows plotted by matplotlib.pyplot.quiver(). There seems to be no parameter to completely remove the shafts, as the arrow head sizes are proportional to the shaft sizes.
How can I remove or hide the shafts, so the arrowhead is the only visible component?
import matplotlib.pyplot as plt
u = v = 2
plt.quiver(0, 0, u, v, angles='xy', scale_units='xy', scale=1)
plt.axis([-u-1, u+1, v-1, v+1])
Upvotes: 3
Views: 1542
Reputation: 5579
One approach is to set the arrowhead size headaxislength
and headlength
such that the head completely covers the shaft. The lengths here are proportional to 'xy', the vector lengths, so we have to scale 1. / width
(the inverse proportionality) by the vector length, np.sqrt(u**2 + v**2)
import matplotlib.pyplot as plt
import numpy as np
u = v = 2
length = np.sqrt(u**2 + v**2)
width=0.005
hal = hl = 1. / width * length
plt.quiver(0, 0, u, v, angles='xy', scale_units='xy', scale=1,
headwidth=hl,
headaxislength=hal,
headlength=hl,
width=width)
plt.axis([-2, u+1, -2, v+1])
Upvotes: 5