有没有办法在matplotlib中绘制表情符号?

问题描述 投票:2回答:1

有人知道在使用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)
python matplotlib seaborn emoji
1个回答
0
投票

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

plt.text(.5,.5,'😀 😃 😄 😁 😆 😅 😂 🤣 ☺️ 😊 😇',fontsize=20)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.