-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_animation.py
43 lines (34 loc) · 969 Bytes
/
draw_animation.py
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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
num_frames = 200
is_binary = True
# 读取数据
xps = []
for frame in range(num_frames):
if is_binary:
xp = np.load(f"results/xp_{frame}.npy")
else:
xp = np.loadtxt(f"results/xp_{frame}.txt")
xps.append(xp)
# 创建一个图像窗口
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection="3d")
# 更新函数
def update(frame):
ax.clear() # 清除旧图像
ax.set_xlim(0.2, 0.8)
ax.set_ylim(0.2, 0.8)
ax.set_zlim(0, 0.3)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.set_box_aspect([2, 2, 1])
ax.text2D(0.05, 0.95, f"frame: {frame}", transform=ax.transAxes)
xp = xps[frame]
ax.scatter(xp[0, :], xp[1, :], xp[2, :], c="b")
return (ax,)
# 创建一个动画对象
ani = FuncAnimation(fig, update, frames=num_frames, interval=50, blit=True)
# 展示动画
plt.show()