0
0
Matplotlibdata~10 mins

Why multiple plots per figure matter in Matplotlib - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a figure with two subplots side by side.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, [1])
plt.show()
Drag options to blanks, or click blank then click option'
A4
B1
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 will create only one plot.
Confusing rows and columns.
2fill in blank
medium

Complete the code to plot data on the first subplot.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
axs[[1]].plot([1, 2, 3], [4, 5, 6])
plt.show()
Drag options to blanks, or click blank then click option'
A0
B1
C2
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes an error or plots on the second subplot.
Using 2 causes an index error.
3fill in blank
hard

Fix the error in the code to plot on both subplots.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
[1].plot([1, 2, 3], [4, 5, 6])
axs[1].plot([1, 2, 3], [6, 5, 4])
plt.show()
Drag options to blanks, or click blank then click option'
Aaxs[1]
Bplt
Caxs[0]
Dfig
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call plot directly on axs causes an error.
Confusing fig and axs.
4fill in blank
hard

Fill both blanks to create a figure with 2 rows and 1 column and plot on the second subplot.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots([1], [2])
axs[1].plot([10, 20, 30], [3, 2, 1])
plt.show()
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 1 row and 2 columns instead.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each subplot index to the number of points plotted if the points are more than 2.

Matplotlib
points = [1, 2, 3, 4]
result = {i: len(points) for i in range([1]) if len(points) [2] [3]
Drag options to blanks, or click blank then click option'
A3
B>
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using range(3) excludes the last index.
Using '<' instead of '>' changes the condition.
Using 3 instead of 2 in the condition.