-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
87 lines (68 loc) · 1.83 KB
/
display.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
83
84
85
86
87
# -*- coding: utf-8 -*-
import threading
import sys
import time
import numpy as np
import matplotlib.pyplot as plt
#TODO faire compatibilité entre python 2.7 et python 3.5
plotLines = False;
def plot_from_file(filename, color) :
fileContent = open(filename, 'r')
lines = fileContent.readlines()
listX = list()
listY = list()
for line in lines :
element = line.split(";")
listX.append(float(element[1]))
listY.append(float(element[2]))
global plotLines
if plotLines :
plt.plot(listX, listY, color=color)
else :
plt.scatter(listX, listY, color=color)
def plot_from_cin() :
plt.axis('equal')
plt.ion()
plt.show()
buffersX = dict()
buffersY = dict()
plots = dict()
sleepCount = 0
for input_line in sys.stdin :
name, values = input_line.split(":")
elements = values.split(";")
if not plots.has_key(name) :
plots[name], = plt.plot([float(elements[1])], [float(elements[2])], 'r')
buffersX[name] = list()
buffersY[name] = list()
else :
line = plots[name]
buffersX[name].append(float(elements[1]))
buffersY[name].append(float(elements[2]))
if len(buffersX[name]) > 40 :
xdata = np.append(line.get_xdata(), buffersX[name])
ydata = np.append(line.get_ydata(), buffersY[name])
line.set_data(xdata, ydata)
buffersX[name] = list()
buffersY[name] = list()
sleepCount += 1
if sleepCount > len(plots) :
plt.pause(0.01)
sleepCount = 0
plt.close()
if __name__ == '__main__' :
if "--line" in sys.argv :
plotLines = True
if "--realtime" in sys.argv :
plot_from_cin()
else :
plt.axis('equal')
plot_from_file('files/earth', 'r')
plot_from_file('files/mars', 'g')
plot_from_file('files/sun', 'b')
plot_from_file('files/jupiter', 'b')
"""
plot_from_file('files/body1', 'g')
plot_from_file('files/body2', 'b')
plot_from_file('files/body3', 'r')"""
plt.show()