How to plot (high quality) emoji in matplotlib? [duplicate]

旧城冷巷雨未停 提交于 2019-12-04 05:23:02

问题


I have the following dictionary:

a = {'❤': 10, '👨‍👩‍👦‍👦': 23, '👹': 13, '🙅🏽': 10, '😡': 13}

I want to plot the emojis as a bar, and draw them on the bar. At first I did like here (with annotate), but it looks bad, and it doesn't support some emojis.

import matplotlib.pyplot as plt
ax = plt.subplot(111)
ax.bar(range(1,6), a.values())
for label, x, y in zip(a.keys(), range(1,6), a.values()):
    plt.annotate(
        label, 
        xy=(x, y), xytext=(10,10),
        textcoords='offset points', ha='right', va='bottom',
        bbox=dict(boxstyle='round,pad=0.5', alpha=0),
        fontname='Segoe UI Emoji',
        fontsize=20)

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.set_xticks([])
plt.show()

As I said, looks bad:

How can I plot the emojis such that they will look good with matplotlib?

The best option would be using a different font in matplotlib that will support those emojis (I tried using some different values for plt.rcParams['font.family'] with no success), but if it doesn't exists images would work too (but how?)

I don't want to start web scraping the images and labeling them (because I'm pretty sure someone already did it).

I'm using python 3, Spyder IDE, matplotlib version 2.0.2 with anaconda.

Any suggestions?

来源:https://stackoverflow.com/questions/49171947/plot-emoji-as-pictures-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!