gpt4 book ai didi

python - 如何使用 contourf() 制作动画?

转载 作者:太空狗 更新时间:2023-10-29 17:58:42 26 4
gpt4 key购买 nike

我正在尝试为一些时间相关数据的空间坐标的 wigner 函数设置动画。 wigner 函数是二维的,所以我使用 contourf() 来绘制它。我将数据存储在 HDF5 文件中,可以即时制作 Wigner 分布,但我不知道如何制作动画。我能找到的所有动画教程和示例(例如 this onethis one)都严格适用于线图。具体来说,他们的 animate(i) 函数使用 line.set_data(),我似乎找不到 contourf() 的等效函数.

如何为使用 contourf() 制作的图像制作动画?

什么是 contourf() 等同于 set_data()

最佳答案

FuncAnimation 有一个简单的方法:您必须具有清除轴并根据帧号绘制新轮廓的功能。不要忘记将 blit 设置为 False

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

DATA = np.random.randn(800).reshape(10,10,8)


fig,ax = plt.subplots()

def animate(i):
ax.clear()
ax.contourf(DATA[:,:,i])
ax.set_title('%03d'%(i))

interval = 2#in seconds
ani = animation.FuncAnimation(fig,animate,5,interval=interval*1e+3,blit=False)

plt.show()

关于python - 如何使用 contourf() 制作动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23070305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com