Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a figure and a single axes using matplotlib.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.figure() which only creates a figure without axes.
Using plt.plot() which is for plotting data, not creating figure or axes.
✗ Incorrect
The plt.subplots() function creates a figure and axes together.
2fill in blank
mediumComplete the code to set the title of the axes to 'My Plot'.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.[1]('My Plot')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
title() which is a pyplot function, not an axes method.Using
show() which displays the plot.✗ Incorrect
The set_title() method sets the title of the axes.
3fill in blank
hardFix the error in the code to plot a line on the axes.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.[1]([1, 2, 3], [4, 5, 6]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
show() as a method on axes which causes error.Using
figure() which creates a new figure, not plotting.✗ Incorrect
The plot() method draws a line plot on the axes.
4fill in blank
hardFill both blanks to create a figure with 2 rows and 1 column of axes.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots([1], [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns.
Using more than 2 rows or columns when only 2x1 is needed.
✗ Incorrect
The arguments to plt.subplots() specify rows and columns of axes.
5fill in blank
hardFill both blanks to create a dictionary comprehension that maps each axes to its index if the index is greater than 0.
Matplotlib
axes_dict = {ax:: i[1] i in range(3) if i [2] 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 's' instead of colon for key-value separator.
Using '<' instead of '>' in the condition.
✗ Incorrect
This dictionary comprehension uses ax: i for i in range(3) if i > 0 syntax.