-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
executable file
·72 lines (66 loc) · 1.99 KB
/
graph.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
def plot(fnm):
"""line-plot showing how compression level impacts file size and conpression speed
Parameters
----------
results_file : str
name of pickle format file to plot
"""
basenm = os.path.basename(fnm)
basenm = os.path.splitext(basenm)[0]
print('Plotting '+basenm)
s = 0;
fig, ax = plt.subplots()
ax.set_title(basenm)
ax.set_xlabel('Days Since Injury')
ax.set_ylabel('Age At Injury')
with open(fnm,'r') as source:
#next() skips first line (header information)
next(source)
for line in source:
fields = line.split('\t')
s += 1
#-2: ignore 1st column (id): M2004 70.2 131 222
#-2: ignore 2nd column (age): M2004 70.2 131 222
nvisits = len(fields) - 2
ageAtInjury = float(fields[1]);
x, y = np.random.random(size=(2,nvisits))
for v in range(nvisits):
days = int(fields[v+2])
#y[v] = s;
y[v] = ageAtInjury;
x[v] = days;
#print(ageAtInjury, days)
#ax.plot(x, y, 'r+-')
if nvisits == 1:
ax.plot(x, y, 'r+-')
elif nvisits == 2:
ax.plot(x, y, 'b+-')
else:
ax.plot(x, y, 'g+-')
#plt.show()
#plt.savefig(basenm + '.pdf')
plt.savefig(basenm + '.png')
if __name__ == '__main__':
"""Plot multiple sessions for each modality
Parameters
----------
fnm : str
(optional) .tab file to view
"""
if len(sys.argv) > 1:
plot(sys.argv[1])
quit()
pth = os.getcwd()
for file in os.listdir(pth):
if file.startswith('.'):
continue;
fnm = os.path.join(pth, file);
if not os.path.isfile(fnm):
continue;
if file.endswith(".tab"):
plot(fnm)