控制matplotlib图像的焦点
Controlling focus of matplotlib image
我正在尝试使用 PCA 来注释我在 2d 中为 Word2Vec 建模的单词。
变量 result
包含以下值:
array([[ 0.01632784, 0.01212493],
[ 0.00070532, 0.01451515],
[-0.0055863 , -0.00661636],
[-0.01106532, -0.0157193 ],
[-0.01473162, 0.00611054],
[-0.01046929, 0.01837107],
[-0.01007252, -0.00692229],
[ 0.00529983, -0.0078546 ],
[ 0.00972514, -0.0030543 ],
[ 0.01812323, -0.01013864],
[-0.00453239, -0.00411107],
[-0.00108769, -0.00255492],
[ 0.0009 , 0.00191122],
[ 0.00646378, 0.00393857]], dtype=float32)
列表words
是:
'Text',
'of',
'the',
'first',
'document',
'second',
'made',
'longer',
'Number',
'three',
'This',
'is',
'number',
'four']
我试图在其坐标中绘制单词的部分代码:
import matplotlib.pyplot as plt
for i,word in enumerate(words):
plt.annotate(word, xy=(result[i,0], result[i,1]))
plt.show()
当我尝试绘制这些单词时,x 轴和 y 轴分别从 (0,1) 和 (0,1) 开始显示。如果我只能从 (0,0.2) 和 (0,0.2) 或任何其他方式只显示图像中存在点的部分,那会更好。
您需要在绘图轴上设置一个范围:
for i,word in enumerate(words):
plt.annotate(word, xy=(result[i,0], result[i,1]))
plt.ylim(-0.04, 0.05)
plt.xlim(-0.04, 0.05)
plt.show()
您可以使用它来设置 x 和 y 限制
axes.set_xlim([0,0.2])
axes.set_ylim([0,0.2])
我正在尝试使用 PCA 来注释我在 2d 中为 Word2Vec 建模的单词。
变量 result
包含以下值:
array([[ 0.01632784, 0.01212493],
[ 0.00070532, 0.01451515],
[-0.0055863 , -0.00661636],
[-0.01106532, -0.0157193 ],
[-0.01473162, 0.00611054],
[-0.01046929, 0.01837107],
[-0.01007252, -0.00692229],
[ 0.00529983, -0.0078546 ],
[ 0.00972514, -0.0030543 ],
[ 0.01812323, -0.01013864],
[-0.00453239, -0.00411107],
[-0.00108769, -0.00255492],
[ 0.0009 , 0.00191122],
[ 0.00646378, 0.00393857]], dtype=float32)
列表words
是:
'Text',
'of',
'the',
'first',
'document',
'second',
'made',
'longer',
'Number',
'three',
'This',
'is',
'number',
'four']
我试图在其坐标中绘制单词的部分代码:
import matplotlib.pyplot as plt
for i,word in enumerate(words):
plt.annotate(word, xy=(result[i,0], result[i,1]))
plt.show()
当我尝试绘制这些单词时,x 轴和 y 轴分别从 (0,1) 和 (0,1) 开始显示。如果我只能从 (0,0.2) 和 (0,0.2) 或任何其他方式只显示图像中存在点的部分,那会更好。
您需要在绘图轴上设置一个范围:
for i,word in enumerate(words):
plt.annotate(word, xy=(result[i,0], result[i,1]))
plt.ylim(-0.04, 0.05)
plt.xlim(-0.04, 0.05)
plt.show()
您可以使用它来设置 x 和 y 限制
axes.set_xlim([0,0.2])
axes.set_ylim([0,0.2])