-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathhenon_animation.py
More file actions
40 lines (32 loc) · 909 Bytes
/
henon_animation.py
File metadata and controls
40 lines (32 loc) · 909 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
40
'''
henon_animation.py
Animating 20000 iterations of the Henon function
'''
import matplotlib.pyplot as plt
from matplotlib import animation
def transform(p):
x,y = p
x1 = y + 1.0 - 1.4*x**2
y1 = 0.3*x
return x1, y1
def update_points(i, x, y, plot):
plot.set_data(x[:i], y[:i])
return plot,
if __name__ == '__main__':
p = (0, 0)
x = [p[0]]
y = [p[1]]
for i in range(10000):
p = transform(p)
x.append(p[0])
y.append(p[1])
fig = plt.gcf()
ax = plt.axes(xlim = (min(x), max(x)),
ylim = (min(y), max(y)))
plot = plt.plot([], [], 'o')[0]
anim = animation.FuncAnimation(fig, update_points,
fargs=(x, y, plot),
frames = len(x),
interval = 25)
plt.title('Henon Function Animation')
plt.show()