Pyplot动画

通过调用 pause 在绘图命令之间。

这里显示的方法只适用于简单、低性能的使用。对于要求更高的应用程序,请查看 animation 模块和使用它的示例。

注意呼叫 time.sleep 而不是 pausenot 工作。

frame 49
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(19680801)
data = np.random.random((50, 50, 50))

fig, ax = plt.subplots()

for i in range(len(data)):
    ax.cla()
    ax.imshow(data[i])
    ax.set_title("frame {}".format(i))
    # Note that using time.sleep does *not* work here!
    plt.pause(0.1)

脚本的总运行时间: (0分8.491秒)

关键词:matplotlib代码示例,codex,python plot,pyplot Gallery generated by Sphinx-Gallery