title: Animation of Histograms in Matplotlib
body: <p>I am working on creating an animation of multiple histograms in Python, however I am unable to do so. I have tried using plt.pause and the time.sleep commands available on python, but to no success. Here is the code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  %matplotlib inline
  import numpy as np
  import math
  import random
  from numpy import zeros
  from time import sleep
  m = 1
  g = 9.8
  b = 0.1
  A = math.sqrt((m*g)/b)
  f=1000
  a=[0]*f
  z=np.zeros(f)
  
  def velocity(tvel, vvel):
      return(A - (math.pow(vvel,1)/A)+(random.randint(-500,500)))
  for k in range(0,f):
      endtime = 100
      steps = 1000
      h = endtime/steps
      timearr = np.linspace(0,endtime,steps)
      vIni = 0
      v = vIni
      varr= []
      for t in timearr:
          varr.append(v)
          v1 = h*velocity(t,v)
          v2 = h*velocity((t+(h/2)), (v+(v1/2)))
          v3 = h*velocity((t+(h/2)), (v+(v2/2)))
          v4 = h*velocity((t+(h/2)), (v+(v3/2)))
          v = v+((1.0/6.0)*(v1+(2*v2)+(2*v3)+v4))
      xrandom=np.zeros(len(varr))
      xrandom[0]=0
      c=0
  
      for i in range(0,len(varr)-1):
          c=c+((varr[i]+varr[i+1])/2)*0.01
          xrandom[i+1]=c
      a[k]=xrandom
  for o in range(len(a)):
      for i in range(0,f):
          z[i]=a[i][o]
      plt.hist(z,bins=150,normed=True)
  plt.show()
  </code></pre>
  
  <p>Essentially what this code does is that it plots 1000 different histograms. What I would like to do is create an animation that will show each histogram after the other (in order) with a fixed frame with relevant bounds. How should I proceed?</p>