0
0
Matplotlibdata~10 mins

Axes creation with add_subplot 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 subplot in a figure.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.[1](111)
plt.show()
Drag options to blanks, or click blank then click option'
Asubplot
Badd_subplot
Caddplot
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subplot' instead of 'add_subplot' on the figure object.
Using 'plot' which is for plotting data, not creating axes.
2fill in blank
medium

Complete the code to create a 2x2 grid of subplots and select the second subplot.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot([1])
plt.show()
Drag options to blanks, or click blank then click option'
A222
B212
C122
D221
Attempts:
3 left
💡 Hint
Common Mistakes
Using '221' which selects the first subplot.
Using '212' which is 2 rows, 1 column, 2nd subplot.
3fill in blank
hard

Fix the error in the code to correctly add a subplot to the figure.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.[1](1, 2, 1)
plt.show()
Drag options to blanks, or click blank then click option'
Aadd_subplot
Bsubplot
Caddplot
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subplot' which is a pyplot function, not a figure method.
Using 'addplot' which does not exist.
4fill in blank
hard

Fill both blanks to create a 3x1 grid and select the second subplot.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.[1]([2])
plt.show()
Drag options to blanks, or click blank then click option'
Aadd_subplot
B312
C311
Dsubplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subplot' instead of 'add_subplot'.
Using '311' which selects the first subplot.
5fill in blank
hard

Fill all three blanks to create a 2x3 grid and select the fourth subplot.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.[1]([2], [3], 4)
plt.show()
Drag options to blanks, or click blank then click option'
Aadd_subplot
B2
C3
Dsubplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subplot' instead of 'add_subplot'.
Swapping rows and columns arguments.