understanding experimental data def fitdata(inputfile)massesdistances getdata(inputfiledistances pylab array(distancesmasses pylab array(massesforces masses* pylab plot(forcesdistances'bo'label 'measured displacements'pylab title('measured displacement of spring'pylab xlabel('|force(newtons)'pylab ylabel('distance (meters)'#find linear fit , pylab polyfit(forcesdistances predicteddistances *pylab array(forcesb / pylab plot(forcespredicteddistanceslabel 'displacements predicted by\nlinear fitk str(round( ))pylab legend(loc 'best'figure fitting curve to data the call fitdata('springdata txt'produces the plot on the right it is interesting to observe that very few points actually lie on the least-squares fit this is plausible because we are trying to minimize the sum of the squared errorsrather than maximize the number of points that lie on the line stillit doesn' look like great fit let' try cubic fit by adding to fitdata #find cubic fit , , , pylab polyfit(forcesdistances predicteddistances *(forces** *forces** *forces pylab plot(forcespredicteddistances' :'label 'cubic fit'this produces the plot on the left the cubic fit looks like much better model of the databut is itprobably not in the technical literatureone frequently sees plots like this that include both raw data and curve fit to the data all too oftenhoweverthe authors then