![]() |
VOOZH | about |
Grids in Matplotlib are intersecting lines that provide a structured reference for data points, improving readability and interpretation of plots. grid() function in the Pyplot module is used to configure grid lines in a plot.
matplotlib.pyplot.grid(b=True, color='grey', linewidth=1.4, axis='', linestyle='-.')
Parameters:
Returns: It does not return anything; it modifies the existing plot by adding a grid.
grid() function can enable or disable grid lines, display major or minor grid lines, and customize color, linewidth, and linestyle.
Example 1: Grid vs No Grid
Output
Explanation:
You can modify color, linewidth, and linestyle for better visualization.
Example 2: Custom Grid Lines
Output
Explanation:
Matplotlib allows us to display gridlines only for the x-axis or y-axis.
Use axis='x' to enable grid lines only along the x-axis.
Output
Explanation:
Use axis='y' to enable grid lines only along the y-axis.
Output
Explanation: