-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphex
executable file
·66 lines (52 loc) · 1.96 KB
/
graphex
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
#!/usr/bin/env python
# Simple way to make a scatter plot of numbers in a text file
# example usage: graphex "F1 score for threshold (\S+) is (\S+)\(P (\S+), R (\S+)\)"
# X Y1 Y2 Y3
# will make a scatter plot of X vs Y1, X vs Y2, and X vs Y3
# If only one field is given, it will automatically number starting from 0.
# You can name fields now too:
# graphex "Z: (?P<Z>\d+) X: (?P<X>\d+) Y: (?P<Y>\d+)"
# will graph X vs Z and X vs Y.
# graphex "(?P<cats>\S+) (?P<dogs>\S+) (?P<rats>\S+)"
# Since there's no field named 'x' or 'X', it will use automatic numbering.
# graphex "\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+(?P<Y>0.\d+)\s+[0-9.]+\s+(?P<Z>0.\d+)\s+\((?P<X>[0-9.]+)\)"
# Extracts f-scores and regularization from cvlm
# Dependencies:
# matplotlib: http://matplotlib.sourceforge.net/
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
import sys, re, pylab
regex = re.compile(sys.argv[1])
points = []
match_index = 0
names = None
for line in sys.stdin:
match = regex.search(line)
if match:
groupdict = match.groupdict()
if groupdict:
names = sorted(groupdict.keys())
items = sorted(groupdict.items())
if not ('x' in groupdict or 'X' in groupdict):
items.insert(0, ('X', match_index))
all_values = [float(value) for key, value in items]
else:
all_values = map(float, match.groups())
if len(all_values) == 1:
all_values = [match_index] + all_values
points.append(all_values)
match_index += 1
colors = iter('rgb')
if not points:
print("Error: didn't match any lines")
raise SystemExit
transformed = list(zip(*points))
x = transformed[0]
for y in transformed[1:]:
pylab.scatter(x, y, c=next(colors))
for item in sorted(zip(x, y)):
print(item)
if names:
pylab.legend(tuple(names[1:]))
pylab.show()