-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·60 lines (52 loc) · 1.51 KB
/
plot.py
File metadata and controls
executable file
·60 lines (52 loc) · 1.51 KB
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
#!/usr/bin/python3
import numpy as np
from matplotlib.animation import FuncAnimation, FFMpegWriter
import matplotlib.pyplot as plt
import csv
import time
class Cycle:
def __init__(self, fishes, x, y, weight):
self.fishes = fishes
self.x = x
self.y = y
self.weight = weight
cycles = []
with open('fish_positions.csv','r') as positions_csv:
plots = csv.reader(positions_csv, delimiter=',')
cycle_num = 0
fishes = []
x = []
y = []
weights = []
for row in plots:
if (plots.line_num == 1):
continue
if (int(row[0]) > cycle_num):
cycles.append(Cycle(fishes, x, y, weights))
cycle_num = int(row[0])
fishes = []
x = []
y = []
weights = []
fishes.append(int(row[2]))
x.append(float(row[3]))
y.append(float(row[4]))
weights.append(float(row[5]) / 500.0)
cycles.append(Cycle(fishes, x, y, weights))
plt.ioff()
figure = plt.figure()
lines_plotted = plt.plot([[0] for x in cycles], [[0] for y in cycles], "bo", fillstyle="none")
plt.xlim(-30, 30)
plt.ylim(-30, 30)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Fish positions')
def animation(frame):
for i, line in enumerate(lines_plotted):
line.set_xdata([frame[1].x])
line.set_ydata([frame[1].y])
plt.legend(lines_plotted,[f'Cycle {frame[0] + 1}'], loc = 'upper right')
anim_created = FuncAnimation(figure, animation, frames=enumerate(cycles),save_count=len(cycles), interval=25)
writervideo = FFMpegWriter(fps=10)
anim_created.save('fish_positions.mp4', writer=writervideo)
plt.close()