from scipy.stats import linregress import numpy as np import matplotlib.pyplot as plt data = np.loadtxt('EP305_lecture_11_data1.dat') xcol, ycol = 0, 1 x, y = data[:,xcol], data[:,ycol] S, y0, r, _, sigmaS = linregress(x,y) print(f'Fitted model is y={S:0.3g} x + {y0:.3g}.') print(f'Uncertainty of the slope is {sigmaS:.3g}.') plt.subplot(121) plt.xlabel('x [l]') plt.ylabel('y [l]') plt.plot(x,y,'kx') plt.plot(x,S * x + y0) plt.subplot(122) plt.xlabel('x [l]') plt.ylabel('residuals [l]') plt.plot(x,y-(S * x + y0),'k') plt.tight_layout()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)