-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimate.py
More file actions
26 lines (21 loc) · 794 Bytes
/
Copy pathanimate.py
File metadata and controls
26 lines (21 loc) · 794 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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
class Animation:
def __init__(self, coordMap, dims):
self.fig, self.ax = plt.subplots()
self.ax.set_xlim(0, dims[0])
self.ax.set_ylim(dims[1])
self.coordMap = coordMap
self.x = list(coordMap.keys())
self.y = list(coordMap.values())
self.line, = self.ax.plot(self.x, self.y, 'ro')
def animate(self, i):
self.line.set_ydata(self.coordMap[i])
return self.line,
def init(self):
self.line.set_ydata(np.ma.array(self.x, mask=True))
return self.line,
def start(self):
_ = animation.FuncAnimation(self.fig, self.animate, self.x, init_func=self.init, interval=100, blit=True)
plt.show()