""" 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 #import sys 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) plt.plot(x,p(x),label=f'degree = {d}') plt.plot(x,y,'ro',label ='data') plt.legend() plt.show() temp, dens = read_data('density_water.txt') fit(temp,dens, [1,2]) """ Terminal>python fit_density_data.py (output is a plot) """