python - 使用 python seaborn 动画热图
问题描述
这真让我抓狂。我正在尝试创建热图的动画,其中每一帧都显示不同的时间戳。我已经创建了数据结构,导入了 ffmpeg,并且我也尝试了另一个包(看起来非常好的赛璐珞)。我尝试了一个带有简单线图的示例,它确实具有动画效果。结果总是一样的:我得到最后一帧,而不是动画。这是我的代码,以防任何人发现错误......提前谢谢你。
- - - - - - - 代码 - - - - - - -
from matplotlib import animation, rc
from IPython.display import HTML
data2 = df[['ProducerName', 'MemOccupied']]
data2 = data2.sort_index().sort_values('ProducerName', kind='mergesort')
data2 = data2[['MemOccupied']]
fig = plt.figure()
camera = Camera(fig)
df_heatmap = pd.DataFrame(data2)
df_heatmap = df_heatmap.dropna()
df_heatmap = df_heatmap.resample('1T').mean()
count = df_heatmap.count()
index_series = df_heatmap.index
def init():
#plt.clf()
ax = sns.heatmap(data2[data2.index == index_series[1]], cbar_kws={'label': 'Memory Occupied (GB)'}, cmap='Blues_r')
ax.set(ylabel=None)
#return (ax,)
def animate(i):
plt.clf()
ax = sns.heatmap(data2[data2.index == index_series[i]], cbar_kws={'label': 'Memory Occupied (GB)'}, cmap='Blues_r')
ax.set(ylabel=None)
#return (ax,)
anim = animation.FuncAnimation(fig = fig, func = animate, init_func=init, frames=count-1,repeat = True, interval = 200)
HTML(anim.to_html5_video())
解决方案
推荐阅读
- php - 使用 Python 的 HTTP 请求中的连接问题
- excel - 如何根据一个单词在一个范围内出现的次数来显示状态?
- python - Tensorflow:在抛出“std::system_error”实例后调用终止
- c - 复制结构的段错误
- c# - 重定向到身份提供者时如何附加 URL 参数
- java - 嵌套在泛型类中的私有类也应该是泛型的吗?
- hadoop - 无法访问 ambari UI
- kotlin - 为什么 Java Sound Clip 在暂停和恢复后不发送 LineListener 事件?
- amazon-web-services - 向弹性 beantalk 实例添加额外的静态 IP
- android - 在贝宝的保险库中保存卡时获取空正文