我有一个方阵列表M[t],其中t的范围从0到N,我希望使用plotly.express创建一个动画热图。每行/列中的条目对应于一个列表a=['a1','a2',... 'aN']。
plotly关于动画的文档相当稀少,主要集中在散点图和条形图上。
https://plotly.com/python/animations/
有一个类似于我的问题发布在
但是,该用户正在使用Jupyter笔记本。我只是在Mac(OS 10.15.4)上使用Python 3.7和IDLE。
我知道如何使用matplotlib或seaborn创建基本的动画,但我喜欢plotly express附带的内置开始/停止按钮。这是我使用的一种方法,但我肯定有更有效的方法可以使用matplotlib.animation:
import numpy as np
import matplotlib.pyplot as plt
#50 matrices, each of size 4-by-4.
N = 50
M = np.random.random((50, 4,4))
#Desired labels for heatmap--not sure where to put.
labels=['a','b','c','d']
fig, ax = plt.subplots()
for t in range(50):
ax.cla()
ax.imshow(M[t])
ax.set_title("frame {}".format(t))
plt.pause(0.1)