Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to automatically generate a bar graph of album word duplicate rates
import matplotlib.pyplot as plt
from matplotlib import rcParams
def plot_album_ngrams(albums, artist):
pos = list(range(len(albums)))
width = 0.25
rcParams.update({'figure.autolayout': True})
fig, ax = plt.subplots(figsize=(12,6))
plt.bar(pos,
[float(row[2])/float(row[1]) for row in albums],
width,
alpha=0.8,
color='r',
label=[row[0] for row in albums])
plt.bar([position + width for position in pos],
[float(row[3])/float(row[1]) for row in albums],
width,
alpha=0.8,
color='g',
label=[row[0] for row in albums])
plt.bar([position + 2 * width for position in pos],
[float(row[4])/float(row[1]) for row in albums],
width,
alpha=0.8,
color='b',
label=[row[0] for row in albums])
ax.set_ylabel('Duplication Rate as % of All Words')
ax.set_title('Word Duplication in ' + artist + ' Discography')
ax.set_xticks([p + 1.5 * width for p in pos])
ax.set_xticklabels([row[0] for row in albums], rotation = 'vertical')
plt.legend(['pairs', 'triplets', 'quadruplets'], loc='upper right')
plt.grid()
plt.savefig(artist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.