Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 156
Kernel: Python 3 (Anaconda)
%matplotlib inline import numpy as np import matplotlib.pyplot as plt import scipy.odr as odr import math import re fileName = "CPM-DIS.csv" myArray = np.genfromtxt("CPM-DIS.csv", delimiter=',') print (myArray) counts = myArray[:,0] distance = myArray[:,1]*1e-3 error = myArray[:,2] print (counts) print (distance) print (error) for line in open("CPM-DIS.csv", 'r').readlines(): if line[0] == '#': print (line)
[[ 1508.7706 12. 16.5476302 ] [ 435.2264 37. 9.15743694] [ 177.9615 62. 5.70908761] [ 114.5655 87. 3.8928353 ] [ 82.223 112. 2.79834985] [ 62.5957 137. 2.08855684]] [ 1508.7706 435.2264 177.9615 114.5655 82.223 62.5957] [ 0.012 0.037 0.062 0.087 0.112 0.137] [ 16.5476302 9.15743694 5.70908761 3.8928353 2.79834985 2.08855684] #CPM, DIS, #Error
r = np.sort(np.array(distance)) def model(params, r): Ix = params[0] return (Ix/(r**2) + 4.27939) params = np.array((.155,)) raxis = np.linspace(0.145,0.01,100)
figFile = re.sub(r'csv$', "png", fileName) print ("figFile = ", figFile) fig = plt.figure(figsize=(15,5)) ax = fig.add_subplot(111) plt.errorbar(distance, counts, yerr=error, fmt = '.') ax.set_xlabel("DISTANCE (M))") ax.set_ylabel("COUNTS PER MINUTE") ax.set_title("CPM VS. DISTANCE") ax.grid() (slope, intercept) = np.polyfit(distance, counts, 1,0) print ("Slope is: ", slope) print ("The intercept is: ", intercept) ax.plot(raxis, model(params, raxis), 'r-') #jnk = ax.legend() fig.savefig(figFile)
figFile = CPM-DIS.png Slope is: -9546.60651429 The intercept is: 1108.11263531
Image in a Jupyter notebook