0
0
Matplotlibdata~10 mins

Nested subplots with subfigures 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 subfigures using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(constrained_layout=True)
subfigs = fig.subfigures(1, [1])
plt.show()
Drag options to blanks, or click blank then click option'
A1
B3
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 for the number of subfigures.
Confusing rows and columns in subfigures.
2fill in blank
medium

Complete the code to add a 2x2 grid of subplots inside the first subfigure.

Matplotlib
axs = subfigs[0].subplots([1], 2)
plt.show()
Drag options to blanks, or click blank then click option'
A4
B2
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or 3 instead of 2 for the number of rows.
Confusing rows and columns.
3fill in blank
hard

Fix the error in the code to add a title to the second subfigure.

Matplotlib
subfigs[[1]].suptitle('Second Subfigure')
plt.show()
Drag options to blanks, or click blank then click option'
A2
B0
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 or 3 which are out of range for two subfigures.
Using 0 which is the first subfigure.
4fill in blank
hard

Fill both blanks to create a 1x3 grid of subplots inside the second subfigure.

Matplotlib
axs2 = subfigs[1].subplots([1], [2])
plt.show()
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns.
Using 2 instead of 1 for rows.
5fill in blank
hard

Fill all three blanks to plot a line on the first subplot of the first subfigure.

Matplotlib
axs.flat[[1]].plot([2], [3])
plt.show()
Drag options to blanks, or click blank then click option'
A0
B[1, 2, 3, 4]
C[10, 20, 25, 30]
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0 for the first subplot.
Swapping x and y data lists.