Matplotlib: Animate 2D Array

后端 未结 1 1549
灰色年华
灰色年华 2021-01-15 20:21

I have some trouble to animate a 2D Array:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
arr=[]
for i in range(         


        
相关标签:
1条回答
  • 2021-01-15 20:54

    Oh thanks, it was easyer then I expected.

    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()
    
    0 讨论(0)
提交回复
热议问题