Challenge - 5 Problems
Grid Lines Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Grid lines style and visibility
What is the output of this code snippet regarding grid lines on the plot?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.grid(True, linestyle='--', color='red') plt.savefig('output.png') plt.close() print('Grid lines are visible with dashed red style')
Attempts:
2 left
💡 Hint
Check the parameters passed to plt.grid() for style and color.
✗ Incorrect
The plt.grid() function is called with True to enable grid lines, linestyle='--' for dashed lines, and color='red' for red color. So the output message matches the actual grid style.
❓ data_output
intermediate2:00remaining
Number of grid lines shown on a plot
Given this code, how many vertical grid lines will appear on the plot?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([0, 1, 2, 3], [10, 20, 25, 30]) ax.set_xticks([0, 1, 2, 3]) ax.grid(True, axis='x') plt.close()
Attempts:
2 left
💡 Hint
Count the number of x-ticks set and how grid lines correspond to ticks.
✗ Incorrect
Grid lines appear at each x-tick. Since 4 x-ticks are set, 4 vertical grid lines will appear.
🔧 Debug
advanced2:00remaining
Identify the error in grid line configuration
What error does this code raise when run?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.grid(True, linestyle='dotted', color='green') plt.show()
Attempts:
2 left
💡 Hint
Check if 'dotted' is a valid linestyle in matplotlib.
✗ Incorrect
No error is raised. Matplotlib recognizes 'dotted' as a valid linestyle (equivalent to ':'), so dotted green grid lines are displayed.
❓ visualization
advanced2:00remaining
Effect of grid line alpha transparency
Which option best describes the visual effect of setting grid line alpha to 0.1?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.grid(True, alpha=0.1) plt.savefig('grid_alpha.png') plt.close()
Attempts:
2 left
💡 Hint
Alpha controls transparency; lower alpha means more transparent.
✗ Incorrect
Alpha value 0.1 means grid lines are mostly transparent, so they appear faint but visible.
🧠 Conceptual
expert2:00remaining
Understanding grid line layering in matplotlib
When multiple grid lines are drawn on a plot with overlapping styles, which matplotlib parameter controls whether grid lines appear above or below plot elements?
Attempts:
2 left
💡 Hint
Think about which parameter controls drawing order in matplotlib.
✗ Incorrect
The 'zorder' parameter controls the drawing order of plot elements, including grid lines, determining if they appear above or below other elements.