-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotPoints.py
82 lines (62 loc) · 1.59 KB
/
plotPoints.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
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
import sys
import matplotlib.pyplot as plt
import csv
import os
if len(sys.argv) < 4 or not sys.argv[1] in ['points', 'result']:
print "Usage: plot-clusters.py (points|result) <src-file> <pdf-file-prefix>"
sys.exit(1)
inFile = sys.argv[1]
inFile = sys.argv[2]
outFilePx = sys.argv[3]
inFileName = os.path.splitext(os.path.basename(inFile))[0]
outFile = os.path.join(".", outFilePx+"-plot.pdf")
########### READ DATA
cs = []
xs = []
ys = []
minX = None
maxX = None
minY = None
maxY = None
if sys.argv[1] == 'points':
with open(inFile, 'rb') as file:
for line in file:
# parse data
csvData = line.strip().split(' ')
x = float(csvData[0])
y = float(csvData[1])
if not minX or minX > x:
minX = x
if not maxX or maxX < x:
maxX = x
if not minY or minY > y:
minY = y
if not maxY or maxY < y:
maxY = y
xs.append(x)
ys.append(y)
# plot data
plt.clf()
plt.scatter(xs, ys, s=25, c="#999999", edgecolors='None', alpha=1.0)
plt.ylim([minY,maxY])
plt.xlim([minX,maxX])
elif sys.argv[1] == 'result':
with open(inFile, 'rb') as file:
for line in file:
# parse data
csvData = line.strip().split(' ')
c = int(csvData[0])
x = float(csvData[1])
y = float(csvData[2])
cs.append(c)
xs.append(x)
ys.append(y)
# plot data
plt.clf()
plt.scatter(xs, ys, s=25, c=cs, edgecolors='None', alpha=1.0)
plt.ylim([minY,maxY])
plt.xlim([minX,maxX])
plt.savefig(outFile, dpi=600)
print "\nPlotted file: %s" % outFile
sys.exit(0)