I have the following code that plots the word vectors:
import numpy as np
import matplotlib.pyplot as plt
la = np.linalg
words = ['I', 'like', 'enjoy', 'deep', 'learning', 'NLP', 'flying', '.']
X = np.array([ [0,2,1,0,0,0,0,0],
[2,0,0,1,0,1,0,0],
[1,0,0,0,0,0,1,0],
[0,1,0,0,1,0,0,0],
[0,0,0,1,0,0,0,1],
[0,1,0,0,0,0,0,1],
[0,0,1,0,0,0,0,1],
[0,0,0,0,1,1,1,0]])
U, s, Vh = la.svd(X, full_matrices = False)
ax = plt.axes()
for i in range(len(words)):
plt.text(U[i,0],U[i,1],words[i])
ax.arrow(0,0,U[i,0],U[i,1],head_width=0.1, head_length=0.1, fc='lightblue', ec='black')
plt.xlim(-.8,.2)
plt.ylim(-.8,.8)
plt.grid()
plt.title(' Simple SVD word vectors in Python',fontsize=10)
plt.show()
plt.close()
This draws the arrows starting from the origin. However, when I try to plot if from other points.
ax.arrow(-0.8,-0.8,U[i,0],U[i,1],head_width=0.1, head_length=0.1, fc='lightblue', ec='black')
It does not draw the arrows! What is the issue please?
Thank you.
matplotlib.axes.Axes.arrow
:ax.arrow(-0.8, -0.8, (U[i,0] + 0.8), (U[i,1] + 0.8),head_width=0.1, head_length=0.1, fc='lightblue', ec='black')