Python 3D 立方体到 2D GIF



有没有一种明显的方法可以从(20, 455, 500)立方体制作 gif?所以 20 张 455x500 的图像。

绘制一个很容易,但是如果你想看到所有这些,该怎么办?我猜我错过了正确的关键字,因为谷歌搜索这并没有给出解决方案。但我无法想象以前没有人这样做过。

plt.imshow(cube_array[0])
plt.show()

下面是创建 matplotlib 动画的最小示例 从 3D 数据立方体。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
cube_array = np.random.rand(20, 455, 500)
fig = plt.figure()
img = plt.imshow(cube_array[0], animated=True)
def updatefig(i):
img.set_array(cube_array[i])
return img,
ani = animation.FuncAnimation(fig, updatefig, frames=cube_array.shape[0],
interval=25, blit=True)
plt.show()

来源:


https://matplotlib.org/examples/animation/dynamic_image.html https://matplotlib.org/api/_as_gen/matplotlib.animation.FuncAnimation.html

最新更新