-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot.py
25 lines (22 loc) · 1.01 KB
/
plot.py
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
import os
import time
import matplotlib.pylab
import matplotlib.pyplot
class Plotter(object):
def __init__(self):
[x.switch_backend("cairo") for x in [matplotlib.pylab, matplotlib.pyplot]]
self.font = {"fontname": "DejaVu Sans"}
def plot_transcription_result(self, name, data_dict, all_notes):
items = [(float(timestamp), val) for timestamp, val in data_dict.items()]
timestamps, notes = zip(*items)
pitches = [all_notes[x] for x in notes]
matplotlib.pyplot.figure()
matplotlib.pyplot.scatter(timestamps, pitches)
matplotlib.pyplot.yticks(pitches, notes)
matplotlib.pyplot.title(os.path.basename(os.path.normpath(name)), **self.font)
matplotlib.pyplot.xlabel("time (ms)", **self.font)
matplotlib.pyplot.ylabel("note", rotation=0, labelpad=15, **self.font)
# filename = "{0}-{1}.png".format(name, time.strftime("%y%m%d%H%M%s"))
filename = "good.png"
matplotlib.pylab.savefig(filename)
return filename