0
0
Matplotlibdata~10 mins

Figure and Axes mental model 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 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'
Aplot
Bfigure
Cshow
Dsubplots
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.
2fill in blank
medium

Complete 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'
Aset_title
Bset_xlabel
Ctitle
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using title() which is a pyplot function, not an axes method.
Using show() which displays the plot.
3fill in blank
hard

Fix 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'
Ashow
Bscatter
Cplot
Dfigure
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.
4fill in blank
hard

Fill 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'
A2
B1
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns.
Using more than 2 rows or columns when only 2x1 is needed.
5fill in blank
hard

Fill 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'
As
Bfor
C>
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using 's' instead of colon for key-value separator.
Using '<' instead of '>' in the condition.