Calmcode - matplotlib: subplot

Subplot

1 2 3 4 5 6 7 8 9

Sometimes you'd like to make figures in a grid. In these scenarios you may find the plt.subplot command useful. A demonstration of this function is listed below.

import numpy as np
import matplotlib.pylab as plt

plt.figure(figsize=(7,7))
for i, mu in enumerate([0, 1, 2]):
    for j, sigma in enumerate([0.1, 0.2, 0.3]):
        x = np.random.normal(mu, sigma, (1000,))
        plt.subplot(3, 3, 3 * i + j + 1)
        plt.hist(x)
        plt.xlim(-1, 4)