绘制三维的散点图动画
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
# 定义动画每一帧的更新函数
def update(n):
z = (2 * n - 1) / N - 1
x = np.sqrt(1 - z * z) * np.cos(2 * np.pi * n * phi)
y = np.sqrt(1 - z * z) * np.sin(2 * np.pi * n * phi)
ax.scatter(x,y,z, c='r')
ani = animation.FuncAnimation(fig, update, np.arange(1, 100), interval=100, blit=False)
# 保存动图
ani.save('scatter.gif', writer='imagemagick', fps=10)
plt.show()
scatter.gif
参考:
Matplotlib制作动画
网友评论