0
0
Matplotlibdata~20 mins

Grid lines configuration in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Grid Lines Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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')
AGrid lines are visible with dashed red style
BGrid lines are visible with solid blue style
CCode raises a TypeError
DNo grid lines are visible
Attempts:
2 left
💡 Hint
Check the parameters passed to plt.grid() for style and color.
data_output
intermediate
2: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()
A4
B3
C0
D1
Attempts:
2 left
💡 Hint
Count the number of x-ticks set and how grid lines correspond to ticks.
🔧 Debug
advanced
2: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()
AAttributeError: 'NoneType' object has no attribute 'plot'
BTypeError: grid() got an unexpected keyword argument 'linestyle'
CValueError: Invalid linestyle 'dotted'
DNo error, grid lines show dotted green
Attempts:
2 left
💡 Hint
Check if 'dotted' is a valid linestyle in matplotlib.
visualization
advanced
2: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()
AGrid lines are invisible
BGrid lines appear very dark and bold
CGrid lines appear very faint and barely visible
DGrid lines are dashed
Attempts:
2 left
💡 Hint
Alpha controls transparency; lower alpha means more transparent.
🧠 Conceptual
expert
2: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?
Aalpha
Bzorder
Clinestyle
Dcolor
Attempts:
2 left
💡 Hint
Think about which parameter controls drawing order in matplotlib.