Which of the following is used to add gridlines to the background of a plot?
Which of the following is used to add gridlines to the background of a plot?
Solution
✅ Correct Option: 1
plt.grid() in Matplotlib turns on gridlines in the background of a plot. Calling plt.grid(True) or just plt.grid() shows them, and arguments such as axis='x', color and linestyle customise them.
Options 2 and 3: plt.xlabel() and plt.ylabel() only set the text labels of the axes, not gridlines.
Option 4: plt.yticks() sets the positions and labels of the y-axis ticks. Gridlines are drawn at tick positions, but this function does not add them.
Related questions:
2026: 11 May Shift 2
2026: 18 May Shift 2
2025: 3 June Shift 2