Skip to content

Commit 1df0c3f

Browse files
authored
Create animation_color.py
动态的色块
1 parent 843f23b commit 1df0c3f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

animation/animation_color.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#Author: Listen
2+
#!/usr/bin/env python3
3+
#-*- coding:utf-8 -*-
4+
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
import matplotlib.animation as animation
8+
9+
fig = plt.figure()
10+
11+
def f(x, y):
12+
return np.sin(x) + np.cos(y)
13+
14+
x = np.linspace(0, 2 * np.pi, 128)
15+
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
16+
17+
im = plt.imshow(f(x, y), animated=True)
18+
19+
def updatefig(*args):
20+
global x, y
21+
x += np.pi / 15.
22+
y += np.pi / 20.
23+
im.set_array(f(x, y))
24+
return im,
25+
26+
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
27+
plt.show()

0 commit comments

Comments
 (0)