%matplotlib inline from __future__ import print_function, division import matplotlib.pyplot as plt fig = plt.figure() # a new figure window ax = fig.add_subplot(1, 1, 1) # specify (nrows, ncols, axnum) import numpy as np x = np.linspace(0, 10, 1000) y = np.sin(x) ax.plot(x, y) fig # this is required to re-display the figure y2 = np.cos(x) ax.plot(x, y2) fig ax.set_ylim(-1.5, 2.0) fig ax.legend(['sine', 'cosine']) fig ax.set_xlabel("$x$") ax.set_ylabel("$\sin(x)$") ax.set_title("I like $\pi$") fig fig = plt.figure() for i in range(6): ax = fig.add_subplot(2, 3, i + 1) ax.set_title("Plot #%i" % i) fig.subplots_adjust(wspace=0.3, hspace=0.3) fig x = np.linspace(0, 10, 1000) for i in range(6): fig.axes[i].plot(x, np.sin(i * x)) fig # create just a single figure and axes fig, ax = plt.subplots() ax.plot(x, np.sin(x)); fig, ax = plt.subplots(2, 3) # 2x3 grid for i in range(2): for j in range(3): ax[i, j].plot(x, np.sin((3 * i + j) * x)) fig, ax = plt.subplots(2, 3, sharex=True, sharey=True) # 2x3 grid for i in range(2): for j in range(3): ax[i, j].plot(x, np.sin((3 * i + j) * x)) fig = plt.figure(figsize=(8, 8)) gs = plt.GridSpec(3, 3) ax1 = fig.add_subplot(gs[0, :]) ax2 = fig.add_subplot(gs[1, :2]) ax3 = fig.add_subplot(gs[1:, 2]) ax4 = fig.add_subplot(gs[2, 0]) ax5 = fig.add_subplot(gs[2, 1])