Skip to content

Instantly share code, notes, and snippets.

@brienna
Last active April 12, 2024 11:20
Show Gist options
  • Save brienna/3433fdfdca2c7ba7b008381410af8e2f to your computer and use it in GitHub Desktop.
Save brienna/3433fdfdca2c7ba7b008381410af8e2f to your computer and use it in GitHub Desktop.
Plotting emojis with Matplotlib
import matplotlib.pyplot as plt, numpy as np
from matplotlib.font_manager import FontProperties
# Load Apple Color Emoji font
prop = FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')
# Set up plot
freqs = [301, 96, 53, 81, 42]
labels = ['๐Ÿ˜Š', '๐Ÿ˜ฑ', '๐Ÿ˜‚', '๐Ÿ˜„', '๐Ÿ˜›']
plt.figure(figsize=(12,8))
p1 = plt.bar(np.arange(len(labels)), freqs, 0.8, color="lightblue")
plt.ylim(0, plt.ylim()[1]+30)
# Make labels
for rect1, label in zip(p1, labels):
height = rect1.get_height()
plt.annotate(
label,
(rect1.get_x() + rect1.get_width()/2, height+5),
ha="center",
va="bottom",
fontsize=30,
fontproperties=prop
)
plt.show()
@giacomomarchioro
Copy link

Hello, this doesn't work for me I get "RuntimeError: In FT2Font: Could not set the fontsize (error code 0x17)"

@Osrip
Copy link

Osrip commented Apr 12, 2024

Same here... Thanks for the suggestion anyways, hopefully I'll get it to work..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment