-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplot.py
61 lines (56 loc) · 1.67 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import matplotlib.pyplot as plt
import colorsys
import sys, getopt, gc
colors = []
x_list = {}
y_list = {}
dx_list = []
dy_list = []
def build_color(n):
for i in range(n):
x_list[i] = []
y_list[i] = []
colors.append(colorsys.hsv_to_rgb(float(i) / n, 1.0, 0.9))
def plot_from_file():
max_number = 0
colors = 0
while 1:
try:
line = raw_input()
x = [float(s) for s in line.split()]
print x[0], x[1]
number = int(x[2])
d = x[3]
if number not in x_list:
x_list[number] = [x[0]]
y_list[number] = [x[1]]
colors = colors + 1
else:
x_list[number].append(x[0])
y_list[number].append(x[1])
if number > max_number:
max_number = number
step = 0.25;
index = int(round(d / step))
error = d - index * step
if abs(error) < 0.02:
dx_list.append(x[0])
dy_list.append(x[1])
except(EOFError):
break
fig, ax = plt.subplots(figsize=(5.5,5.5))
plt.axis('equal')
plt.rc('pdf', fonttype = 42)
print "Uses ", colors, " colors"
color_count = 0
for i in range(max_number + 1):
if i in x_list:
color = colorsys.hsv_to_rgb(float(color_count) / colors, 1.0, 0.9)
print "Number", i, "'s color is ", color
ax.plot(x_list[i], y_list[i], '.', c=color, aa=True)
color_count = color_count + 1
ax.plot(dx_list, dy_list, '.', c='black', aa=True)
plt.draw()
plt.show()
if __name__ == "__main__":
plot_from_file()