0Pricing
Python Academy · Lesson

Subplots and Layouts

Combine multiple charts.

Why Multiple Charts

Often one chart is not enough. You may want to compare several views side by side, or break a busy plot into smaller panels. Matplotlib calls this arranging multiple axes inside one figure.

The main tool is plt.subplots(rows, cols).

A Grid of Axes

fig, axes = plt.subplots(2, 3) creates a figure with a 2 by 3 grid, giving you six axes. The axes result is a 2D array you index like axes[0][1].

The total panel count is just rows times columns.

rows, cols = 2, 3
total = rows * cols
print('Grid', rows, 'x', cols, '=', total, 'axes')
for r in range(rows):
    for c in range(cols):
        print('panel at', (r, c))

All lessons in this course

  1. Figures and Axes
  2. Line, Bar and Scatter Plots
  3. Customizing Plots
  4. Subplots and Layouts
← Back to Python Academy