Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 for the number of subfigures.
Confusing rows and columns in subfigures.
✗ Incorrect
The code creates one row of subfigures with 2 columns, so the correct argument is 2.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or 3 instead of 2 for the number of rows.
Confusing rows and columns.
✗ Incorrect
To create a 2x2 grid, the number of rows is 2 and columns is 2.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The second subfigure is at index 1 because indexing starts at 0.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns.
Using 2 instead of 1 for rows.
✗ Incorrect
To create a 1 row and 3 columns grid, use 1 and 3 respectively.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0 for the first subplot.
Swapping x and y data lists.
✗ Incorrect
The first subplot is index 0; x values are [1, 2, 3, 4]; y values are [10, 20, 25, 30].