Matplotlib animation either freezes after a few frames or just doesn't work

前端 未结 8 1335
悲哀的现实
悲哀的现实 2020-12-18 06:04

I\'ve been trying for hours to get this simple script working, but nothing I do seems to help. It\'s a slight modification of the most basic animated plot sample code from t

8条回答
  •  庸人自扰
    2020-12-18 07:04

    greetings from the future.

    Here's how you'd do it in python 3:

    import matplotlib
    matplotlib.use('TkAgg') # Qt4Agg gives an empty, black window
    import matplotlib.pylab as plt
    import time
    
    # create initial plot
    z = zeros(10)
    line, = plot(z)
    ylim(-3, 3)
    
    for i in range(60):
        print('frame:', i)
    
        d = randn(10)
        line.set_ydata(d)
        draw()
        #replace time.sleep() with plt.pause()
        plt.pause(0.5)
    
    

    I got rid of the call to ion() and hold(False). I also replaced time.sleep with plt.pause

提交回复
热议问题