Editor

Create a 1x3 Subplot Layout

Advanced · Write the code · 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

Create a figure with 1 row and 3 columns of subplots. Set the figure size to (12, 4). Set the titles of the three subplots to 'Sales', 'Profit', and 'Growth'. Call fig.tight_layout(), then print the shape of the axes array and the three titles.

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# Create 1x3 subplots with figsize (12, 4)
# Set titles for each subplot
# Call tight_layout
# Print axes shape and titles

More Matplotlib Subplots exercises

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