Here we plot the height of the ball during the first second of its movement:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
import numpy as np
def plot_ball():
t = np.linspace(0,1)
plt.figure(figsize=(4,2))
plt.plot(t, ball_height(t))
plt.xlabel('time (sec)')
plt.ylabel('height (meters)')
plt.title('Ball height vs time', fontsize=10)
plt.show()
plot_ball()
The function ball_heigh
used above is defined as follows:
def ball_height(t, v_0=10):
g = 9.81
return v_0*t - 0.5*g*t**2