0
0
Matplotlibdata~10 mins

Unequal subplot sizes in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a figure with two subplots arranged vertically.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots([1], 1)
plt.show()
Drag options to blanks, or click blank then click option'
A3
B2
C1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 creates only one subplot.
Using 3 or 4 creates more subplots than needed.
2fill in blank
medium

Complete the code to set the height ratios of the two subplots to 3 and 1.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1])
plt.show()
Drag options to blanks, or click blank then click option'
A[1, 3]
B[1, 1]
C[2, 2]
D[3, 1]
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of ratios.
Using equal ratios which make subplots equal height.
3fill in blank
hard

Fix the error in the code to create subplots with unequal widths.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2, gridspec_kw=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'width_ratios': [2, 1]}
B{'height_ratios': [2, 1]}
C['width_ratios', [2, 1]]
D{'width_ratio': [2, 1]}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'height_ratios' for horizontal subplots.
Misspelling the key as 'width_ratio'.
Using a list instead of a dictionary.
4fill in blank
hard

Fill both blanks to create a figure with 3 vertical subplots with height ratios 1, 2, and 1.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots([1], 1, gridspec_kw=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A3
B{'height_ratios': [1, 2, 1]}
C{'width_ratios': [1, 2, 1]}
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using width_ratios instead of height_ratios.
Setting wrong number of rows.
5fill in blank
hard

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.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots([1], [2], gridspec_kw=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A2
C{'height_ratios': [2, 1], 'width_ratios': [3, 1]}
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up rows and columns numbers.
Using only height_ratios or width_ratios but not both.