Is there any way to plot emojis in matplotlib?

Viewed 724

Does anybody know how to plot emojis in matplotlib while using windows? I've been struggling to find a solution as most out there seem to be specific for macOS.

Below is my current graph showing emojis plotted in a vector space, but as usual most do not show up.

o

Is there perhaps any fonts already installed with matplotlib that provide emoji support or will I need to install some backend solutions?

Code:

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 Answers

This seems to work for me , but apparently depends on default fonts (eg "Segoe UI Emoji") being installed:

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

enter image description here

Related