forked from andikleen/pmu-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot-normalized.py
executable file
·45 lines (40 loc) · 1.02 KB
/
plot-normalized.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# plot already normalized data
# first column is time stamp
import csv
import matplotlib.pyplot as plt
import sys
import argparse
ap = argparse.ArgumentParser(usage='Plot already normalized CSV data')
ap.add_argument('--output', '-o', help='Output to file. Otherwise show.',
nargs='?')
ap.add_argument('inf', nargs='?', default=sys.stdin, type=argparse.FileType('r'),
help='input CSV file')
args = ap.parse_args()
inf = args.inf
rc = csv.reader(inf)
num = 0
timestamps = []
columns = dict()
for r in rc:
num += 1
if num == 1:
for j in r[1:]:
columns[j] = []
continue
timestamps.append(r[0])
c = 1
for j in columns:
try:
columns[j].append(float(r[c]))
except ValueError:
columns[j].append(float('nan'))
c += 1
for j in columns:
plt.plot(timestamps, columns[j], label=j)
leg = plt.legend()
leg.get_frame().set_alpha(0.5)
if args.output:
plt.savefig(args.output)
else:
plt.show()