-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotAnimated.py
executable file
·52 lines (47 loc) · 1.59 KB
/
plotAnimated.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
#!/usr/bin/env python3
#
# (c) 2018-2025 m4r35n357@gmail.com (Ian Smith), for licencing see the LICENCE file
from sys import argv, stdin, stderr
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def data_gen():
line = stdin.readline()
while line:
p = line.split()
yield float(p[3]), float(p[0]), float(p[1]), float(p[2])
line = stdin.readline()
def line_data():
line_x.set_data(t_data, x_data)
line_y.set_data(t_data, y_data)
line_z.set_data(t_data, z_data)
return line_x, line_y, line_z,
def init():
ax.set_ylim(minimum, maximum)
ax.set_xlim(0, 10)
return line_data()
def update(data):
t, x, y, z, = data
t_data.append(t)
x_data.append(x)
y_data.append(y)
z_data.append(z)
x_min, x_max = ax.get_xlim()
if t >= 0.99 * x_max:
ax.set_xlim(x_min, 1.1 * x_max)
ax.figure.canvas.draw()
return line_data()
print(f'\033[1;30margs \033[0m{len(argv)}\033[1;30m, argv [\033[0;33m', file=stderr, end='')
for i in range(len(argv)):
print(f' {argv[i]}', file=stderr, end='')
print(" \033[1;30m]\033[0m", file=stderr)
if len(argv) != 3:
raise Exception('>>> ERROR! Please supply two parameters: min and max "y" values <<<')
minimum, maximum = float(argv[1]), float(argv[2])
fig, ax = plt.subplots()
line_x, = ax.plot([], [], 'g', lw=1, ms=0)
line_y, = ax.plot([], [], 'y', lw=1, ms=0)
line_z, = ax.plot([], [], 'c', lw=1, ms=0)
ax.grid()
t_data, x_data, y_data, z_data = [], [], [], []
_ = animation.FuncAnimation(fig, update, data_gen, blit=True, interval=10, repeat=False, init_func=init)
plt.show()