Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a figure and axes for subplots.
Data Analysis Python
fig, ax = plt.[1](1, 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.subplot instead of plt.subplots
Using plt.plot which only creates a single plot
Using plt.figure which creates only the figure, no axes
✗ Incorrect
The plt.subplots() function creates a figure and a set of subplots (axes).
2fill in blank
mediumComplete the code to plot a line chart on the first subplot.
Data Analysis Python
ax[[1]].plot(x, y1) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first subplot
Using negative indices incorrectly
Using 2 when only two subplots exist
✗ Incorrect
Index 0 refers to the first subplot in the axes array.
3fill in blank
hardFix the error in the code to set the title of the second subplot.
Data Analysis Python
ax[[1]].set_title('Second Plot')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 which is out of range
Using 0 which is the first subplot
Using negative indices incorrectly
✗ Incorrect
The second subplot is at index 1 in the axes array.
4fill in blank
hardFill both blanks to create subplots with 2 rows and 1 column and plot on the first subplot.
Data Analysis Python
fig, ax = plt.subplots([1], [2]) ax[0].plot(x, y)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns
Using 3 or 4 which creates more subplots than needed
✗ Incorrect
To create 2 rows and 1 column of subplots, use plt.subplots(2, 1).
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
Data Analysis Python
lengths = { [1]: [2] for [3] in words if len([1]) > 3 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Using len(word) as key instead of value
Not filtering words by length
✗ Incorrect
The dictionary comprehension uses word as key, len(word) as value, and iterates over word in words.