为2D数组制作动画我遇到了一些麻烦:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
arr=[]
for i in range(100):
c=np.random.rand(10,10)
arr.append(c)
plt.imshow(arr[45])
我不知道如何为这个数组设置动画: https://matplotlib.org/examples/animation/dynamic_image.html
谢谢周末愉快。
答案 0 :(得分:1)
哦,谢谢,这比我想象的还要容易。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
i=0
im = plt.imshow(arr[0], animated=True)
def updatefig(*args):
global i
if (i<99):
i += 1
else:
i=0
im.set_array(arr[i])
return im,
ani = animation.FuncAnimation(fig, updatefig, blit=True)
plt.show()
感谢jadelord和T先生