""" Ex 6.18 from A Primer on ... Use polyfit from numpy to fit a polynomial to data points read from a file. We reuse the function for reading the file from Ex 5.16. """ import numpy as np import matplotlib.pyplot as plt """ Make sure the file read_density_data.py exists in the same directory as the current file. """ from read_density_data import read_data def fit(x,y,deg): for d in deg: coeff = np.polyfit(x,y,d) p = np.poly1d(coeff) y_poly = p(x) plt.plot(x,y_poly) plt.plot(x,y,'ro') plt.show() temp, dens = read_data('density_water.dat') fit(temp,dens,[1,2]) """ Terminal> python fit_density_data.py Output is a plot """