Exercise 3: By calling plot multiple times, create a single axes showing the line plots of $y=sin(x)$ and $y=cos(x)$ in the interval $[0, 2\pi]$ with 200 linearly spaced $x$ samples.


In [1]:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 200)
plt.plot(x, np.sin(x), color='red')
plt.plot(x, np.cos(x), color='blue')
plt.show()


Exercise 3 continued: Copy the answer from the previous task (plotting $y=sin(x)$ and $y=cos(x)$) and add the appropriate plt.subplot calls to create a figure with two rows of Axes artists, one showing $y=sin(x)$ and the other showing $y=cos(x)$.


In [2]:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 200)

plt.subplot(2, 1, 1)
plt.plot(x, np.sin(x), color='red')

plt.subplot(2, 1, 2)
plt.plot(x, np.cos(x), color='blue')

plt.show()