""" Ex. 5.14 from "A primer on..." Read two columns from a file and plot the result. """ import numpy as np import matplotlib.pyplot as plt x = [] y = [] with open('xy.txt') as infile: for line in infile: xy = line.split() x.append(float(xy[0])) y.append(float(xy[1])) #converting to arrays makes it easier to compute mean y x = np.array(x) y = np.array(y) print(f"Max y = {np.max(y)}, min y = {np.min(y)}, mean = {np.mean(y)}") plt.plot(x,y) plt.show()