Which function is used to create multiple subplots in Matplotlib?
Analysis & Theory
`plt.subplots()` is the recommended way to create multiple subplots in Matplotlib.
What does `plt.subplot(2, 1, 1)` mean?
A
2 rows, 1 column, select 2nd plot
B
1 row, 2 columns, select 1st plot
C
2 rows, 1 column, select 1st plot
D
2 columns, 1 row, select 1st plot
Analysis & Theory
`plt.subplot(2, 1, 1)` means create a figure with 2 rows and 1 column, and activate the 1st subplot.
What is returned by `fig, ax = plt.subplots(2, 2)`?
C
A figure and a 2x2 array of Axes objects
Analysis & Theory
`plt.subplots(2, 2)` returns a figure and a 2D array of 4 Axes objects.
How do you access the bottom-right subplot from `ax = plt.subplots(2, 2)`?
Analysis & Theory
Subplots are accessed using zero-based indexing: bottom-right in a 2x2 grid is `ax[1, 1]`.
What does `sharex=True` do in `plt.subplots()`?
A
Shares the x-axis with all subplots
C
Creates a stacked subplot
Analysis & Theory
`sharex=True` causes all subplots to share the same x-axis ticks and labels.
How can you adjust spacing between subplots?
Analysis & Theory
`plt.tight_layout()` automatically adjusts subplot spacing to prevent overlaps.
Which method is used to add a single subplot in a figure manually?
Analysis & Theory
You can use `fig.add_subplot()` to manually add a subplot to a figure.
What does `fig.suptitle('Main Title')` do?
A
Adds a title to the current subplot
B
Adds a title only to the last subplot
C
Adds a title above all subplots
Analysis & Theory
`fig.suptitle()` adds a common title for the entire figure, above all subplots.
Which parameter in `plt.subplots()` specifies figure size?
Analysis & Theory
`figsize=(width, height)` sets the size of the figure in inches.
What happens if you use `plt.subplot(1, 2, 3)`?
A
You get an error: only 2 subplots allowed
B
It selects the third plot in a 1x2 grid
C
It selects the second plot in a 1x3 grid
D
You get an error: invalid position
Analysis & Theory
`plt.subplot(1, 2, 3)` is invalid since there are only 2 subplots (1 row x 2 cols) — index 3 is out of bounds.