Skip to content

Instantly share code, notes, and snippets.

@brienna
Created January 23, 2019 18:53
Show Gist options
  • Save brienna/edca0a6e5eea8b057190231ec855872b to your computer and use it in GitHub Desktop.
Save brienna/edca0a6e5eea8b057190231ec855872b to your computer and use it in GitHub Desktop.
# Set the backend to use mplcairo
import matplotlib, mplcairo
print('Default backend: ' + matplotlib.get_backend())
matplotlib.use("module://mplcairo.macosx")
print('Backend is now ' + matplotlib.get_backend())
# IMPORTANT: Import these libraries only AFTER setting the backend
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment