-
Notifications
You must be signed in to change notification settings - Fork 4
/
plot_data.py
executable file
·48 lines (34 loc) · 1.05 KB
/
plot_data.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
#!/usr/bin/env python3
import sys
import csv
import numpy as np
import matplotlib.pyplot as plt
def main(file1, file2):
with open(file1) as f:
data1 = [[float(j) for j in i] for i in list(csv.reader(f))]
if file2 is not None:
with open(file2) as f:
data2 = [[float(j) for j in i] for i in list(csv.reader(f))]
cols = list(zip(*data1))
x = cols[0]
ys = cols[1:]
fig, axes = plt.subplots(len(ys), 2 if file2 is not None else 1, sharey="row")
axes = np.atleast_2d(axes)
if file2 is None:
axes = axes.transpose()
for i, y in enumerate(ys):
axes[i, 0].plot(x, y)
if file2 is not None:
cols = list(zip(*data2))
x = cols[0]
ys = cols[1:]
for i, y in enumerate(ys):
axes[i, 1].plot(x, y)
plt.show()
if __name__ == "__main__":
if len(sys.argv) <= 1:
print("Usage: ./plot_data.py <file1.csv> [<file2.csv>]")
else:
file1 = sys.argv[1]
file2 = sys.argv[2] if len(sys.argv) > 2 else None
main(file1, file2)