Editor

Predict the Subplot Configuration

Advanced · Predict the output · from Advanced Matplotlib: Subplots, Dual Axes, Styles, Annotations

From the lesson: Advanced Matplotlib: Subplots, Dual Axes, Styles, Annotations

You know how to create a single chart. But real-world reports rarely have just one. A data analyst might need four charts side by side, each zoomed into a different slice of the same dataset.

Read the lesson

What will this code print? Think carefully about the subplot grid shape and the tight_layout call.

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig, axes = plt.subplots(2, 3, figsize=(15, 10))
for i in range(2):
for j in range(3):
axes[i, j].set_title(f'Plot {i*3 + j + 1}')
print(axes.shape)
print(axes[1, 2].get_title())

More Matplotlib Subplots exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz