Skip to content

Instantly share code, notes, and snippets.

@wesdoyle
Last active September 10, 2016 17:32
Show Gist options
  • Save wesdoyle/fa41fa9fa4ed966b6e2b3cb66b4124df to your computer and use it in GitHub Desktop.
Save wesdoyle/fa41fa9fa4ed966b6e2b3cb66b4124df to your computer and use it in GitHub Desktop.
Method to plot year histogram from iTunes playlist
def plotYearHisto(fileName):
"""
Plot year histogram using XML playlist from iTunes.
"""
plist = plistlib.readPlist(fileName)
tracks = plist['Tracks']
years = []
for trackId, track in tracks.items():
try:
years.append(track['Year'])
except:
pass
if years == []:
print("Playlist file does not contain valid track year data.")
return
x = np.array(years)
plt.plot()
plt.hist(x, bins=20, color='midnightblue')
plt.title('Song Year Histogram for %s' % fileName)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment