-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplot_chromas.py
More file actions
29 lines (25 loc) · 916 Bytes
/
plot_chromas.py
File metadata and controls
29 lines (25 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import jams
import mir_eval
import numpy as np
import matplotlib.pyplot as plt
# create chroma from chord label
def labchroma(l):
r,c,b = mir_eval.chord.encode(l)
return np.roll(c,r)
# plot the chromas of the annotators of song s
def plotchroma(s):
jam = jams.load('jams/' + str(s) + '.jams')
nannotations = len(jam['annotations'])
f, axarr = plt.subplots(nannotations, sharex=False, sharey=True, figsize=(10, 5))
for (ann, ax) in zip(jam['annotations'],axarr):
chroma = np.array([labchroma(lab.value) for lab in ann.data])
im = ax.matshow(chroma.T, aspect='auto', cmap=plt.cm.Blues)
ax.set_ylabel(ann.annotation_metadata.annotator.id)
ax.get_yaxis().set_ticks([])
f.tight_layout()
fname = 'img/' + str(s) + '_chroma.png'
plt.savefig(fname, bbox_inches='tight')
plt.close()
print (fname + ' saved.')
# Example for readme
plotchroma(92)