forked from andikleen/pmu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-normalized.py
executable file
·50 lines (44 loc) · 1.1 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
46
47
48
49
50
#!/usr/bin/env python3
# plot already normalized data
# first column is time stamp
import sys
import argparse
import os
import csv
import matplotlib
if os.getenv("DISPLAY") is None:
matplotlib.use('Agg')
import matplotlib.pyplot as plt
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 = {}
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()