Subplots

Figure 9.3 shows some useful matplotlib features.

#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np

x = np.arange( 0.01, 10, 0.01)
y = np.exp(-(x-5)*(x-5)/3)

fig = plt.figure( 1, figsize = (11.6, 8.2))
plt.figtext( 0.5, 0.95, "A figure containing various plots", va='center', ha = 'center')
plt.subplot(2,2,1)
plt.plot(x, y)
plt.axis([0,10,0,1.2])
plt.ylabel('Gauss')
plt.xlabel('x-Axis')

plt.subplot(2,2,2)
plt.hist(y, 50)
plt.xlabel('x-Axis')

plt.subplot(2,3,4)
plt.plot( x,y, 'b')
plt.axis([0,10,0,1.2])
plt.title( "no log", fontsize = 10,
           x = 0.95, y = 0.85, ha='right', va='top')
plt.grid(True)

plt.subplot(2, 3, 5)
plt.loglog( x, y, 'g')
plt.axis([0,10,0,1.2])
plt.title( "log-x, log-y", fontsize = 10,
           x = 0.95, y = 0.85, ha='right', va='top')
plt.grid(True)

plt.subplot( 2, 3, 6)
plt.semilogx( x, y, 'r--')
plt.axis([0,10,0,1.2])
plt.title( "log-x", fontsize = 10,
           x = 0.95, y = 0.85, ha='right', va='top')
plt.grid(True)

plt.show()

Figure 9.3: SubPlots
\includegraphics[width=20.68cm]{fivePlots.ps}