Complete the code to create a figure with two subplots arranged vertically.
import matplotlib.pyplot as plt fig, axs = plt.subplots([1], 1) plt.show()
We want two subplots stacked vertically, so the number of rows is 2.
Complete the code to set the height ratios of the two subplots to 3 and 1.
import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1]) plt.show()
The height_ratios list sets the relative heights of subplots from top to bottom. [3, 1] means the first subplot is three times taller than the second.
Fix the error in the code to create subplots with unequal widths.
import matplotlib.pyplot as plt fig, axs = plt.subplots(1, 2, gridspec_kw=[1]) plt.show()
The correct key is 'width_ratios' with a list of ratios. Other options are incorrect keys or wrong data types.
Fill both blanks to create a figure with 3 vertical subplots with height ratios 1, 2, and 1.
import matplotlib.pyplot as plt fig, axs = plt.subplots([1], 1, gridspec_kw=[2]) plt.show()
We need 3 rows for 3 vertical subplots and set height_ratios to [1, 2, 1] for unequal heights.
Fill all three blanks to create a figure with 2 rows and 2 columns of subplots, where the first row is twice as tall and the first column is three times as wide.
import matplotlib.pyplot as plt fig, axs = plt.subplots([1], [2], gridspec_kw=[3]) plt.show()
We want 2 rows and 2 columns. The height_ratios set the first row twice as tall, and width_ratios set the first column three times as wide.