Recall & Review
beginner
What does
plt.subplots(rows, cols) do in matplotlib?It creates a figure and a grid of subplots arranged in the specified number of rows and columns. You get a figure object and an array of axes to plot on.
Click to reveal answer
beginner
How do you access the subplot in the second row and first column when using
plt.subplots(2, 3)?You access it with
axes[1, 0] because indexing starts at 0 and axes is a 2D array of shape (2, 3).Click to reveal answer
beginner
What type of object is returned by
plt.subplots()?It returns a tuple: (
figure, axes). figure is the whole drawing area, and axes is either a single Axes object or an array of Axes objects.Click to reveal answer
beginner
How can you create a 1-row, 3-column subplot layout?
Use
fig, axes = plt.subplots(1, 3). This creates one row with three columns of plots side by side.Click to reveal answer
beginner
What happens if you create subplots with
plt.subplots(1, 1)?You get a single Axes object, not an array. So you can use it directly without indexing.
Click to reveal answer
What does
plt.subplots(2, 2) return?✗ Incorrect
plt.subplots(2, 2) returns a figure and a 2x2 array of Axes objects for plotting.
How do you plot on the subplot in the first row, second column of
plt.subplots(3, 3)?✗ Incorrect
Indexing starts at 0, so first row is 0 and second column is 1, so axes[0, 1].
If you create subplots with
plt.subplots(1, 1), what type is axes?✗ Incorrect
With one row and one column, axes is a single Axes object, not an array.
What is the shape of
axes when you run fig, axes = plt.subplots(4, 1)?✗ Incorrect
axes is a 1D array of length 4, not a 2D array, when one dimension is 1.
Which command creates a 2-row, 3-column grid of plots?
✗ Incorrect
plt.subplots(2, 3) creates 2 rows and 3 columns.
Explain how to create a grid of subplots with 2 rows and 3 columns using matplotlib and how to access the subplot in the second row, third column.
Remember indexing starts at 0 for rows and columns.
You got /4 concepts.
Describe what happens when you create subplots with plt.subplots(1, 1) and how it differs from creating multiple subplots.
Think about the shape and type of axes returned.
You got /4 concepts.