Skip to main content

Matplotlib: Adding Grid Lines

In Matplotlib Pyplot grid() function is used to add or configure grids line in the plot.


matplotlib.pyplot.grid(visible=None, which='major', axis='both', **kwargs)


  • visible: It is by default None.
  • which: It is used to apply the changes on the grid lines.
  • axis: It is used to define the axis on which we want to apply the changes.
  • **kwargs: It defines the properties of lines


import matplotlib.pyplot as plt
import numpy as np

x = np.array([2,7,9])



Plot with grid lines

Submitted by devanshi.srivastava on November 23, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.