Block 34: Subplots & Layout
Display multiple plots in a single figure.
Concepts
- plt.subplots(nrows, ncols)
- Sharing axes: sharex, sharey
- plt.tight_layout() to prevent overlap
- ax.twinx() for dual y-axes
Code Examples
See exercise below.
Exercise
Create a 1×2 subplot: histogram on left, scatter on right for the same dataset. Create a 2×2 grid of 4 different chart types for the Iris dataset.
Homework
Explain when to use subplots vs creating separate figures. Wednesday