""" Exercise 5.18 from " A primer on..." Read data from file and plot it. Read data and use numpy tools to fit polynomials to the data. We import the function from exercise 5.16 and use it to read the data from file """ import numpy as np import matplotlib.pyplot as plt import sys from read_density_data import read_density_data #a) def fit(x, y, deg): for d in deg: coeff = np.polyfit(x, y, d) p = np.poly1d(coeff) y_fitted = p(x) plt.plot(x, y_fitted, label=f'Degree {d}') plt.plot(x, y, 'ro', label = 'Data') plt.legend() plt.show() #b) if __name__ == "__main__": filename = sys.argv[1] temp, dens = read_density_data(filename) fit(temp, dens, [1,2])