Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.optimize import curve_fit
- data = np.loadtxt("Combined_dartboard.csv", delimiter=',', skiprows = 1)
- # Changed from "try2darts.csv"
- print(data) # Don't do this
- ValidDart = data[:,1] # Changed from data[1]
- print(ValidDart) # Don't need to print this
- DartStrike = data[:,2]
- print(DartStrike) # Don't need to print this
- Average = DartStrike.mean()
- print("The mean in combined throws: ", Average)
- # Changed from print(Average)
- STD = DartStrike.std(ddof = 1)
- print("The Standard Deviation in combined throws: ", STD)
- # Changed from print(STD)
- uncertaintyofmean = STD/np.sqrt(DartStrike.size)
- print("The Standard Deviation from the mean in combined throws: ",
- uncertaintyofmean)
- # Changed from print(uncertanityofmean)
- Average2 = (sum(DartStrike))/DartStrike.size
- print(Average2)
- sigma = np.sqrt((1/((DartStrike.size)-1))*sum((DartStrike-Average2)**2))
- print(sigma)
- alpha_ = sigma/np.sqrt(DartStrike.size)
- print(alpha_)
- #bin_boundaries = -22.5+3*np.arange(16)
- #print(bin_boundaries)
- fig = plt.figure(figsize= (10,5), dpi=100)
- ax = fig.add_subplot(111)
- plt.hist(DartStrike, bins=40, range=(-20.5,20.5), cumulative=False, bottom=0,
- align="mid",orientation="vertical",color="pink",stacked=False,
- hold=None,data=None,alpha=1 )
- #plt.xlim(-20.5, 20.5)
- # Changed from plt.hist(DartStrike, range= [-24,24],
- # bins= [-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,
- # -5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],
- # align='mid') and removed the xlim
- plt.show() # Added
- plt.close() # Added
- mu = Average2
- dx = 1
- x= np.linspace(mu-sigma*6,mu+sigma*6,int(12*sigma/dx)+1)
- gaussian = np.sqrt(1/(sigma**2*2.*np.pi))*np.exp(-(x-mu)**2/(2.*sigma**2))
- print("Check that PDF adds (almost) to one:", gaussian.sum()*dx)
- # Output for me
- '''
- [[ 1. 1. -4.]
- [ 1. 2. 0.]
- [ 1. 3. 2.]
- ...
- [ 58. 148. 7.]
- [ 58. 149. 7.]
- [ 58. 150. 8.]]
- [ 1. 2. 3. ... 148. 149. 150.]
- [-4. 0. 2. ... 7. 7. 8.]
- The mean in combined throws: 0.41210176484070593
- The Standard Deviation in combined throws: 6.546462392993681
- The Standard Deviation from the mean in combined throws: 0.07008080358281947
- 0.41210176484070593
- 6.546462392993711
- 0.0700808035828198
- Check that PDF adds (almost) to one: 0.9929026704994178
- '''
- # Hitogram looks good, you can fool around with the settings to make it look
- # how you want, I'm still squashing the bugs for mine so I can't confirm any
- # of the gausian stuff for you. If it seems legit than it should be good!
- # I'll see if I can knock this thing out tonight, hopefully I'll have a few
- # things for you tmrw, when ur back from work.
Advertisement
Add Comment
Please, Sign In to add comment