To create a figure with multiple subplots, use add_subplot method on figure, where arguments are nrows, ncols, fignum (fignum is which one to work on, starts at 1).

When all numbers are less than ten, they can be merged into a triple of numbers:

fig = add_subplot(2, 1, 2)

is equivalent to:

fig = add_subplot(212)


In [ ]:
# Example on how to create 2 y-axis drawn on the same plot:
%pylab notebook
import matplotlib.pyplot as plt
import numpy as np

In [ ]:
x = np.arange(0., np.e, 0.01)
y2 = np.exp(-x)
y1 = np.log(x)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1);  # <---note that semicolon supresses extra verbose output
ax1.set_ylabel('Y values for exp(-x)');
ax2 = ax1.twinx()
ax2.plot(x, y2, 'r');
ax2.set_xlim([0, np.e]);
ax2.set_ylabel('Y values for ln(x)');
ax2.set_xlabel("Same X for both exp(-x) and ln(x)");

In [ ]:
# (More stuff in this section about log plots and sharing axis ranges on multiple axes in the same figure)

In [ ]: