【问题标题】:Controlling focus of matplotlib image控制 matplotlib 图像的焦点
【发布时间】:2020-05-21 05:01:00
【问题描述】:

我正在尝试使用 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) 或任何其他方式显示图像中存在点的部分,那就更好了。

【问题讨论】:

    标签: python matplotlib pca


    【解决方案1】:

    您需要在绘图轴上设置一个范围:

    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()
    

    【讨论】:

      【解决方案2】:

      您可以使用它来设置 x 和 y 限制

      axes.set_xlim([0,0.2])
      axes.set_ylim([0,0.2])
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-06
        • 2014-04-29
        相关资源
        最近更新 更多