Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import libraries
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- from wand.image import Image
- from wand.display import display
- # Create 1500 simulations of dies roll
- n= 1500
- # In each simulation , there is one trial more than previous simulation
- avrg = []
- for x in range(2,n):
- m = np.random.randint(1,7,x)
- avrg.append(np.average(m))
- print(avrg[1:10])
- # Function to plot histogram
- def animate(current):
- plt.cla()
- if current == 1500:
- m.event_source.stop()
- plt.hist(avrg[0:current])
- plt.gca().set_title('Expected value of die rolls')
- plt.gca().set_xlabel('Average from die roll')
- plt.gca().set_ylabel('Frequency')
- plt.annotate('Die roll = {}'.format(current), [3,27])
- fig = plt.figure()
- a = animation.FuncAnimation(fig, animate, interval=1)
- a.save('./ani.gif', writer='imagemagick', fps=10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement