Challenge - 5 Problems
Subplot Customization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1: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())
Attempts:
2 left
💡 Hint
Check which subplot index is used to set the title.
✗ Incorrect
The code sets the title of axs[1] to 'Second Plot'. The print statement outputs this exact string.
❓ data_output
intermediate1: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()))
Attempts:
2 left
💡 Hint
Count the number of positions passed to set_xticks for the first subplot.
✗ Incorrect
The first subplot has ticks set at [0,1,2,3], so it will have 4 ticks.
❓ visualization
advanced2: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)])
Attempts:
2 left
💡 Hint
Look at the linestyle argument passed to grid for each subplot.
✗ Incorrect
The first subplot uses linestyle='--' which is dashed. The others use dotted ':' and solid '-'.
🔧 Debug
advanced1: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)
Attempts:
2 left
💡 Hint
Check the index used to access axs array.
✗ Incorrect
axs is a 2x2 array, so valid indices are 0 to 3. axs[4] is out of range causing IndexError.
🚀 Application
expert2: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)
Attempts:
2 left
💡 Hint
Use the correct method to set the axes background color.
✗ Incorrect
The correct method to set the background color of a subplot is set_facecolor(). Other options are invalid or do not exist.