Recall & Review
beginner
What is the main purpose of using unequal subplot sizes in matplotlib?
To allocate different amounts of space to each subplot, allowing some plots to be larger or smaller based on their importance or data detail.
Click to reveal answer
beginner
Which matplotlib function helps create subplots with custom size ratios?
The
gridspec module, especially GridSpec, allows you to define the relative sizes of rows and columns for subplots.Click to reveal answer
intermediate
How do you specify different height ratios for subplots in matplotlib?
Use
GridSpec with the height_ratios parameter, passing a list of numbers that represent relative heights for each row.Click to reveal answer
intermediate
What is the difference between
plt.subplot() and GridSpec when creating subplots?plt.subplot() creates subplots with equal sizes by default, while GridSpec allows flexible control over subplot sizes and layout.Click to reveal answer
beginner
Show a simple code snippet to create two vertical subplots with the top subplot twice as tall as the bottom one.
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs = GridSpec(2, 1, height_ratios=[2, 1])
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
ax1.plot([1, 2, 3], [1, 4, 9])
ax2.plot([1, 2, 3], [9, 4, 1])
plt.show()Click to reveal answer
Which matplotlib module allows you to create subplots with unequal sizes?
✗ Incorrect
GridSpec is the module designed for flexible subplot layouts including unequal sizes.
How do you control the relative height of subplots in a vertical layout?
✗ Incorrect
height_ratios sets relative heights for rows in GridSpec.
What happens if you do not specify size ratios when creating subplots?
✗ Incorrect
By default, subplots have equal sizes if no ratios are specified.
Which parameter would you use to make the left subplot wider than the right one in a horizontal layout?
✗ Incorrect
width_ratios controls relative widths of columns in GridSpec.
What is the benefit of using unequal subplot sizes?
✗ Incorrect
Unequal sizes help emphasize some plots by allocating more space.
Explain how to create vertical subplots with different heights using matplotlib.
Think about how to tell matplotlib to make one subplot taller than another.
You got /4 concepts.
Describe the difference between using plt.subplot() and GridSpec for subplot layouts.
Consider which method gives you more control over subplot sizes.
You got /4 concepts.