0
0
Matplotlibdata~20 mins

Individual subplot customization in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Subplot Customization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of subplot title customization
What will be the title of the second subplot after running this code?
Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
axs[0].set_title('First Plot')
axs[1].set_title('Second Plot')
plt.close(fig)
print(axs[1].get_title())
ASecond Plot
BFirst Plot
CPlot 2
Dnull
Attempts:
2 left
💡 Hint
Check which subplot index is used to set the title.
data_output
intermediate
1:30remaining
Number of ticks on customized subplot
After running this code, how many x-axis ticks will the first subplot display?
Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1)
axs[0].set_xticks([0, 1, 2, 3])
axs[1].set_xticks([0, 1])
plt.close(fig)
print(len(axs[0].get_xticks()))
A4
B2
C5
D3
Attempts:
2 left
💡 Hint
Count the number of positions passed to set_xticks for the first subplot.
visualization
advanced
2:00remaining
Identify subplot with customized grid style
Which subplot will display a dashed grid after running this code?
Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 3)
axs[0].grid(true, linestyle='--')
axs[1].grid(true, linestyle=':')
axs[2].grid(true, linestyle='-')
plt.close(fig)
print([axs[i].get_xgridlines()[0].get_linestyle() for i in range(3)])
AFirst subplot
BSecond subplot
CThird subplot
Dnull of them
Attempts:
2 left
💡 Hint
Look at the linestyle argument passed to grid for each subplot.
🔧 Debug
advanced
1:30remaining
Identify error in subplot label customization
What error will this code raise when customizing subplot labels?
Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
axs[0].set_xlabel('X axis')
axs[1].set_ylabel('Y axis')
axs[4].set_title('Invalid subplot')
plt.close(fig)
AIndexError
BAttributeError
CTypeError
DNo error
Attempts:
2 left
💡 Hint
Check the index used to access axs array.
🚀 Application
expert
2:00remaining
Customize individual subplot background colors
Given this code, which option correctly sets the background color of the middle subplot to light gray?
Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 3)
# Customize background color here
plt.close(fig)
Aaxs[1].set_facecolor('lightgray')
Baxs[1].set_background('lightgray')
Caxs[1].facecolor = 'lightgray'
Daxs[1].background_color('lightgray')
Attempts:
2 left
💡 Hint
Use the correct method to set the axes background color.