forked from lferry007/LargeVis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
44 lines (34 loc) · 1.21 KB
/
plot.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
import numpy
import matplotlib.pyplot as plt
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-input', default = '', help = 'input file')
parser.add_argument('-label', default = '', help = 'label file')
parser.add_argument('-output', default = '', help = 'output file')
parser.add_argument('-range', default = '', help = 'axis range')
args = parser.parse_args()
label = []
if args.label != '':
for line in open(args.label):
label.append(line.strip())
N = M = 0
all_data = {}
for i, line in enumerate(open(args.input)):
vec = line.strip().split(' ')
if i == 0:
N = int(vec[0])
M = int(vec[1])
elif i <= N:
if args.label == '':
label.append(0)
all_data.setdefault(label[i-1], []).append((float(vec[-2]), float(vec[-1])))
colors = plt.cm.rainbow(numpy.linspace(0, 1, len(all_data)))
for color, ll in zip(colors, sorted(all_data.keys())):
x = [t[0] for t in all_data[ll]]
y = [t[1] for t in all_data[ll]]
plt.plot(x, y, '.', color = color, markersize = 1)
if args.range != '':
l = abs(float(args.range))
plt.xlim(-l, l)
plt.ylim(-l, l)
plt.savefig(args.output, dpi = 500)