""" Exercise 5.11 from "A primer on..." Modify the previous exercise to set the axis lengths manually, based on the maximum values of t and y. This is something we rarely need to do, but it is necessary when making animation and may also be useful in other tasks, for instance when comparing different plots. """ import numpy as np import matplotlib.pyplot as plt import sys g = 9.81 v0_list = sys.argv[1:] t_max = 0 y_max = 0 for v0 in v0_list: v0 = float(v0) t_max = 2 * v0 / g t = np.linspace(0, t_max, 101) y = v0 * t - 0.5 * g * t**2 plt.plot(t, y) #find max values for t and y if max(t) > t_max: t_max = max(t) if max(y) > y_max: y_max = max(y) plt.xlabel('time (s)') plt.ylabel('height (m)') plt.axis([0, t_max, 0, y_max*1.05]) plt.show()