# import the libraries we need for number crunching and plotting import numpy as np import matplotlib.pyplot as pl #generate random data for the experiment #generate a series w from zero to 20 w = np.arange(0.0, 21.0, 1.0) #generate a linear series y=mx+c using m=5 and c=10 and add some random offsets to it d = 5.0 * w + 10.0 + np.random.normal(0.0, 5.0, w.size) # find thevalues of m and c from the randowm data generated m,c=np.polyfit(w,d,1) #plot the dataset and the linear fit derived above pl.plot(w, m * w + c, 'b-', label='Best fit line') pl.plot(w,d,'k.') pl.show()