Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import matplotlib.animation as animation
  3. import numpy as np
  4. import scipy.stats as stats
  5.  
  6. plt.style.use('seaborn-pastel')
  7.  
  8.  
  9. n = 100
  10. p_iter = 0.05
  11.  
  12. fig = plt.figure()
  13. ax = plt.axes(xlim=(0, 1), ylim=(0, 1))
  14.  
  15. x_axis = np.arange(0, 1+1/n, 1/n)
  16. line, = ax.plot([], [], lw=2)
  17.  
  18.  
  19. def init():
  20.     line.set_data(x_axis, [])
  21.     return line,
  22.  
  23. def animate(i):
  24.     cur_p = p_iter * i
  25.     y_axis = np.array([stats.binom.pmf(k, n, cur_p) for k in range(0, n+1)])
  26.     line.set_data(x_axis, y_axis)
  27.     plt.title('p = {0}'.format(np.around(cur_p, 2)))
  28.     return line,
  29.  
  30.  
  31.  
  32.  
  33. cframes = int(1 /p_iter) + 1
  34. anim = animation.FuncAnimation(fig, animate, init_func=init,
  35.                                frames=cframes, interval=250, blit=True)
  36.  
  37. anim.save('output/Bi(n, p).gif', writer='imagemagick')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement