Animation of histograms in subplot

前端 未结 3 911
后悔当初
后悔当初 2020-12-06 08:51

I have the following animated subplots that simulate histograms of four different distributions:

import numpy
from matplotlib.pylab import *
import matplotli         


        
3条回答
  •  -上瘾入骨i
    2020-12-06 09:18

    Got it!

    My iterating over n was the culprit. This does what I expected:

    def updateData(curr):
    
        curr2=100+curr*5 
    
        #if curr == n: 
        #    a.event_source.stop()
    
        ax1.hist(x1[:curr2], normed=True, bins=20, alpha=0.5)
        ax2.hist(x2[:curr2], normed=True, bins=20, alpha=0.5)
        ax3.hist(x3[:curr2], normed=True, bins=20, alpha=0.5)
        ax4.hist(x4[:curr2], normed=True, bins=20, alpha=0.5)
    
    simulation = animation.FuncAnimation(fig, updateData, frames=900, interval=10)
    
    plt.show()
    

提交回复
热议问题