title: Animate convergence of binomial to poisson in Python
body: <p>I've been trying to animate the convergence of a binomial p.m.f. to a Poisson one, but couldn't figure it out with matplotlib's animate. Here's my best try:</p>
  <pre><code>from random import randint
  import numpy as np
  import pandas as pd
  from scipy import stats
  import matplotlib.pyplot as plt
  from matplotlib.animation import FuncAnimation
  
  fig, ax = plt.subplots()
  
  def animate(i):
      p = 0.01    
      bino = stats.binom(i,p)
      x = np.arange(0,i)
      y1 = bino.pmf(x)
      possion = stats.poisson(i*p)
      y2 = possion.pmf(x)
      ax.clear()
      line1, = ax.plot(x, y1)
      line2, = ax.plot(x, y2)
      ax.set_xlim([0,i])
      ax.set_ylim([0,max(y1)])
      return line1, line2
  
  ani = FuncAnimation(fig, animate, frames=range(10,100), interval=5000, repeat=False)
  
  plt.show()
  </code></pre>