【发布时间】:2020-06-16 14:46:58
【问题描述】:
我正在尝试通读documentation 的matplotlib.animation.FuncAnimation 以制作热图动画。
当我运行下面的代码时,我没有收到任何错误,并且确实出现了热图,但它似乎没有动画。
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
# generate random noise for the heatmap
rnd_data = np.random.normal(0, 1, (500, 100, 100))
fig, ax = plt.subplots(figsize=(12,10))
def my_func(i):
sns.heatmap(rnd_data[i])
anim = matplotlib.animation.FuncAnimation(fig=fig, func=my_func, frames=200, interval=500, blit=False)
plt.show()
这段代码的结果似乎是rnd_data的单帧,即第一个数组rnd_data[0]。我尝试将 frames 和 interval 的数量更改为更大的数字,因为我认为它的动画速度太快了,我看不到,但这似乎不起作用。
我在这里做错了吗?我想当我为这样的数据集绘制热图时,我应该能够看到绘图的像素发生变化并像白噪声一样四处移动,但它不起作用。如何为热图制作动画?
【问题讨论】:
标签: python python-3.x matplotlib animation heatmap