Subplots and constrained layout
3.11.2
Arrange several plotting areas and share scales when the measurements are comparable.
On this page
Organize plots in a grid
subplots creates a Figure plus Axes. For a 1×2 grid, unpack the two Axes or use squeeze=False to always receive a 2D array. Use layout="constrained" to help fit axes labels and titles.
import matplotlib.pyplot as plt
fig, (left, right) = plt.subplots(1, 2, layout="constrained")
left.plot([2, 4, 3])
left.set_title("Daily volume")
right.bar(["Tea", "Cake"], [6, 4])
right.set_title("Item volume")
plt.show()
Download image