Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make arrow head shape symmetric regardless of the angle of the arrow in matplotlib

The following code yields the figure below. The shape of the arrowhead is dependent on the angle of the arrow. How can I make all of the arrow heads the same symmetric shape? I am asking specifically for Python 3 but general solutions are welcome.

import matplotlib.pyplot as plt
plt.arrow(0, 0, .5, .5, head_width = .1)
plt.arrow(0, 0, .2, .5, head_width = .1)
plt.arrow(0, 0,  0, .5, head_width = .1)
plt.axis((-1, 1, -1 ,1))
plt.show()

arrow head demo

like image 894
dylnan Avatar asked Oct 02 '18 16:10

dylnan


1 Answers

It's not possible with plt.arrow. I guess the reason plt.arrow still exists is purely for backwards compatibility. Arrows are better produced by matplotlib.patches.FancyArrowPatch. The easiest way to get such FancyArrowPatch in your plot is via plt.annotate.

import matplotlib.pyplot as plt

prop = dict(arrowstyle="-|>,head_width=0.4,head_length=0.8",
            shrinkA=0,shrinkB=0)

plt.annotate("", xy=(.5,.5), xytext=(0,0), arrowprops=prop)
plt.annotate("", xy=(.2,.5), xytext=(0,0), arrowprops=prop)
plt.annotate("", xy=(.0,.5), xytext=(0,0), arrowprops=prop)

plt.axis((-1, 1, -1 ,1))
plt.show()

enter image description here

Arrows are currently a bit underdocumented, but there is still a plan to write up some complete tutorial or guide.

like image 185
ImportanceOfBeingErnest Avatar answered Oct 22 '22 14:10

ImportanceOfBeingErnest