-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
39 lines (31 loc) · 1016 Bytes
/
Copy pathplotter.py
File metadata and controls
39 lines (31 loc) · 1016 Bytes
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
from os import pread
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
UPDATE_INTERVAL = 100
GRAPHED_POINTS = 50
style.use('fivethirtyeight')
fig = plt.figure()
axis1 = fig.add_subplot(1, 1, 1)
def animate(i):
graph_data = open('data_output.txt', 'r').read()
lines = graph_data.split('\n')
predator_line = []
prey_line = []
cycles = []
for line in lines:
if len(line) > 1:
predator, prey, cycle = line.split(',')
predator_line.append(float(predator))
prey_line.append(float(prey))
cycles.append(cycle)
if len(predator_line) > GRAPHED_POINTS:
predator_line = predator_line[-GRAPHED_POINTS:]
prey_line = prey_line[-GRAPHED_POINTS:]
cycles = cycles[-GRAPHED_POINTS:]
axis1.clear()
axis1.plot(cycles, predator_line, label="predators")
axis1.plot(cycles, prey_line, label="prey")
axis1.legend()
animate_graph = animation.FuncAnimation(fig, animate, interval = UPDATE_INTERVAL)
plt.show()