I've created a bar plot of emoji frequencies using matplotlib
in Jupyter Notebook. I've also tested this in the Terminal.
Code:
freqs = [90, 29, 5, 29, 15]
labels = [, , , , ]
# Plot the figure
plt.figure(figsize=(12, 8))
ax = pd.Series(freqs).plot(kind='bar', color='pink', width=0.8)
ax.set_title('Most Frequently Used Emojis')
ax.set_ylabel('Frequency', fontsize=15)
ax.set_xlabel('Emojis', fontsize=15)
plt.tick_params(
axis='x',
which='both',
bottom=False,
top=False,
labelbottom=False
)
new_ylim = ax.get_ylim()[1]+30
ax.set_ylim((0, new_ylim))
rects = ax.patches
# Make labels
for rect, label in zip(rects, labels):
height = rect.get_height()
plt.annotate(
label,
(rect.get_x() + rect.get_width()/2, height+5),
ha="center",
va="bottom",
fontsize=30
)
plt.show()
As you can see, the emojis don't show up.
After adding
import matplotlib.font_manager as mfm
emoji_font = mfm.FontProperties(fname="/System/Library/Fonts/Apple Color Emoji.ttc")
and fontproperties = emoji_font
as an option in plt.annotate
, it throws RuntimeError: In FT2Font: Could not set the fontsize
. The figure will not display.
How can I get emojis to show in a bar plot in Jupyter Notebook?
If I use a font such as Symbola, the emojis seem like they will look like this:
I don't want these emojis. Nor do I want to load images. They should be the real Apple emojis.
Other questions that are still unanswered or are answered using the incorrect emoji depiction from above:
- How to plot (high quality) emoji in matplotlib?
- Non-ASCII characters in Matplotlib
- matplotlib: annotate plot with Emoji labels
- Emoji in Matplotlib figures on OS X
- Emojis in matplotlibs xticks
- plot emoji as pictures in matplotlib
None of them get the Apple emojis onto the graph. Why can't this happen? Am I missing something? Is it possible with another plotting library?