Skip to content

Commit 87ee72c

Browse files
authored
Create first_try.py
和正弦曲线运动的比没有持续下去
1 parent de2ab48 commit 87ee72c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

animation/first_try.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#Author: Listen
2+
#!/usr/bin/env python3
3+
#-*- coding:utf-8 -*-
4+
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
import matplotlib.animation as animation
8+
9+
fig, ax = plt.subplots()
10+
xdata = []
11+
ydata = []
12+
line, = plt.plot([], [], '-', animated=True)
13+
14+
def init():
15+
ax.set_xlim(0, 10 * np.pi)
16+
ax.set_ylim(-1.1, 1.1)
17+
return line,
18+
19+
def update(frame):
20+
xdata.append(frame)
21+
ydata.append(np.sin(frame))
22+
line.set_data(xdata, ydata)
23+
return line,
24+
25+
ani = animation.FuncAnimation(fig,update,frames=np.linspace(0, 10 * np.pi, 500),
26+
init_func=init, blit=True, interval=10)
27+
28+
plt.show()

0 commit comments

Comments
 (0)