SHARE
TWEET

Untitled

a guest Jun 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # import libraries
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import matplotlib.animation as animation
  5. from wand.image import Image
  6. from wand.display import display
  7.  
  8. # Create 1500 simulations of dies roll
  9. n= 1500
  10.  
  11. # In each simulation , there is one trial more than previous simulation
  12. avrg = []
  13. for x in range(2,n):
  14.         m = np.random.randint(1,7,x)
  15.         avrg.append(np.average(m))
  16.  
  17.         print(avrg[1:10])
  18.  
  19. # Function to plot histogram
  20.         def animate(current):
  21.                 plt.cla()
  22.                 if current == 1500:
  23.                         m.event_source.stop()
  24.  
  25.                 plt.hist(avrg[0:current])
  26.  
  27.                 plt.gca().set_title('Expected value of die rolls')
  28.                 plt.gca().set_xlabel('Average from die roll')
  29.                 plt.gca().set_ylabel('Frequency')
  30.  
  31.                 plt.annotate('Die roll = {}'.format(current), [3,27])
  32.  
  33.         fig = plt.figure()
  34.  
  35. a = animation.FuncAnimation(fig, animate, interval=1)
  36. a.save('./ani.gif', writer='imagemagick', fps=10)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top