0
0
Matplotlibdata~10 mins

Individual subplot customization 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 with 2 subplots using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, [1])
plt.show()
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 for the number of subplots.
Confusing rows and columns in plt.subplots.
2fill in blank
medium

Complete the code to set the title of the first subplot to 'First Plot'.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
axs[[1]].set_title('First Plot')
plt.show()
Drag options to blanks, or click blank then click option'
A0
B-1
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first subplot index.
Using negative indices incorrectly.
3fill in blank
hard

Fix the error in the code to set the x-label of the second subplot to 'X Axis'.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
axs.[1](1).set_xlabel('X Axis')
plt.show()
Drag options to blanks, or click blank then click option'
Aplot
Bindex
Csubplot
D__getitem__
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call axs.subplot(1) which is not valid.
Using axs.plot(1) which is for plotting, not indexing.
4fill in blank
hard

Fill both blanks to set the y-label of the first subplot to 'Y Axis' and change its background color to light gray.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
axs[[1]].set_ylabel('Y Axis')
axs[[2]].set_facecolor('lightgray')
plt.show()
Drag options to blanks, or click blank then click option'
A0
B1
C2
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indices for the two actions.
Using invalid indices like 2 which is out of range.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

Matplotlib
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
A:
Blen(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma instead of colon between key and value.
Using wrong comparison operator in the condition.
Using word instead of len(word) as value.