Created
August 19, 2017 14:37
-
-
Save benrules2/a8caa4ee672f87f2229144c2bddbf1fe to your computer and use it in GitHub Desktop.
Script to automatically generate a bar graph of album word duplicate rates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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