Apr 25, 2013

Multiple Plots in Matplotlib

To plot multiple subplots, use the subplot command. This commands takes in the following arguments
(a) Number of rows
(b) Number of columns
(c) Current plot number
In [127]: plt.figure(1)

In [128]: plt.subplot(2,2,1)

In [129]: x=np.arange(-np.pi, np.pi,0.1)

In [130]: plt.plot(x,np.sin(x))

In [132]: plt.subplot(2,2,2)

In [133]: plt.plot(x,np.cos(x))

In [134]: plt.subplot(2,2,3)

In [135]: plt.plot(x,np.tan(x))

In [136]: plt.subplot(2,2,4)

In [138]: plt.plot(x,1/np.cos(x))