Matplotlib simple and two head arrows
I would like to make a simple arrow and an arrow with two arrows. I used the following to create a simple arrow, but I doubt this is the easiest way:
import matplotlib.pyplot as plt
arr_width = .009 # I don't know what unit it is here.
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(range(10))
ax1.arrow(1, 1, 0, .5, width = arr_width, head_width = 3 * arr_width,
head_length = 9 * arr_width)
plt.show()
I cannot find how to make two head arrows using this method.
+3
source to share
1 answer
You can create a double-headed arrow using a method annotate
with an empty text annotation and setting arrowprops
dict to include arrowstyle='<->'
as shown below:
import matplotlib.pyplot as plt
plt.annotate(s='', xy=(1,1), xytext=(0,0), arrowprops=dict(arrowstyle='<->'))
plt.show()
+5
source to share