有什么办法可以在matplotlib中绘制表情符号?

时间:2020-05-09 18:18:59

标签: python windows matplotlib seaborn emoji

有人知道在使用Windows时如何在matplotlib中绘制表情符号吗?我一直在努力寻找解决方案,因为大多数解决方案似乎都是针对macOS的。

下面是我当前的图形,其中显示了在矢量空间中绘制的表情符号,但通常不会显示。

o

matplotlib可能已经安装了提供表情符号支持的字体,还是我需要安装一些后端解决方案?

代码:

def display_pca_scatterplot(model, words=None, sample=0):
    if words == None:
        if sample > 0:
            words = np.random.choice(list(model.vocab.keys()), sample)
        else:
            words = [ word for word in model.vocab ]

    prop = FontProperties(fname='/usr/share/fonts/truetype/noto/Apple Color Emoji.ttc')

    word_vectors = np.array([model[w] for w in words])

    twodim = PCA().fit_transform(word_vectors)[:,:2]

    sb.set_style("darkgrid")
    plt.figure(figsize=(10,10))
    plt.scatter(twodim[:,0], twodim[:,1]) #, edgecolors='w', color='w')
    for word, (x,y) in zip(words, twodim):
        plt.text(x+0.0, y+0.0, word, fontsize=20) #fontproperties=prop)

1 个答案:

答案 0 :(得分:1)

这似乎对我有用,但显然取决于所安装的默认字体(例如“ Segoe UI Emoji”):

plt.text(0,.5,'? ? ? ? ? ? ? ? ☺️ ? ?',fontsize=20)

enter image description here