mahmood
mahmood

Reputation: 24715

Position of arrow head in matplotlib

The following code draws arrows from center to some points. However, as you can see, the position of the arrow head is after the point. I want to put that before the point. How can I fix that.

import matplotlib.pyplot as plt
import numpy as np

a = np.array([
[-0.108,0.414],
[0.755,-0.152],
],)

x, y = a.T
plt.scatter(x, y)
plt.xlim(-1,1)
plt.ylim(-1,1)

ax = plt.axes()
ax.arrow(0, 0, a[0,0], a[0,1], head_width=0.05, head_length=0.1, fc='k', ec='k')
ax.arrow(0, 0, a[1,0], a[1,1], head_width=0.05, head_length=0.1, fc='k', ec='k')
plt.grid(True)
plt.show()

enter image description here

Upvotes: 3

Views: 1838

Answers (1)

BigBen
BigBen

Reputation: 50008

Use length_includes_head=True.

ax.arrow(0, 0, a[0,0], a[0,1], head_width=0.05, head_length=0.1, fc='k', 
         ec='k', length_includes_head=True)
ax.arrow(0, 0, a[1,0], a[1,1], head_width=0.05, head_length=0.1, fc='k', 
         ec='k', length_includes_head=True)

Output:

enter image description here

Upvotes: 5

Related Questions