I have a list of square matrices, M[t], where t ranges from 0 to N and I wish to create an animated heatplot using plotly.express. The entries in each row/column correspond to a list, a=['a1','a2',...'aN']
The plotly documentation on animation is fairly sparse and focuses on just scatterplots and barplots
https://plotly.com/python/animations/
A question similar to mine was posted at
How to animate a heatmap in Plotly
However, the user is working in a Jupyter notebook. I'm simply using Python 3.7 with IDLE on a Mac (OS 10.15.4)
I know how to create a basic animation using matplotlib or seaborn, but I like the built-in start/stop buttons that come with plotly express. Here's one approach I use, but I'm sure there are more efficient ways using 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)
Does this work for you?
UPDATE In case you need to add a
Pause
button