Friday, October 10, 2025
HomeLanguagesMatplotlib.axis.Axis.get_gridlines() function in Python

Matplotlib.axis.Axis.get_gridlines() function in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.

matplotlib.axis.Axis.get_gridlines() Function

The Axis.get_gridlines() function in axis module of matplotlib library is used to get the grid lines as a list of Line2D instance.
 

Syntax: Axis.get_gridlines(self) 

Parameters: This method does not accepts any parameters. 
 

Return value: This method returns the grid lines as a list of Line2D instance. 

Below examples illustrate the matplotlib.axis.Axis.get_gridlines() function in matplotlib.axis:
Example 1:
 

Python3




# Implementation of matplotlib function 
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
import random
    
fig, ax2 = plt.subplots()
x = []
  
for i in range(1,11):
    j = random.randint(1,10)
    x.append(i*j)
ax2.plot(x)
  
print("Value of get_gridlines() :")
for i in ax2.xaxis.get_gridlines():
    print(i)
    
fig.suptitle("Matplotlib.axis.Axis.get_gridlines()\
Function Example", fontsize = 12, fontweight ='bold'
  
plt.show()


Output: 
 

 

Value of get_gridlines() :
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))

Example 2:
 

Python3




# Implementation of matplotlib function 
from matplotlib.axis import Axis  
import matplotlib.pyplot as plt 
import matplotlib.text 
      
fig, ax = plt.subplots() 
      
ax.plot([5,1], label="Label 1"
ax.plot([3,0], label="Label 2"
      
legend = ax.legend(loc="upper right"
offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
   
ax.annotate("String - Info"
            xy = (0,0),  
            size = 14
            xycoords = 'figure fraction'
            xytext = (0,-20),  
            textcoords = offset,  
            horizontalalignment = 'right',  
            verticalalignment = 'top'
     
fig.canvas.draw() 
ax.grid()
    
print("Value of get_gridlines() :")
for i in ax.yaxis.get_gridlines():
    print(i)
    
fig.suptitle("Matplotlib.axis.Axis.get_gridlines()\
Function Example", fontsize = 12, fontweight ='bold'
  
plt.show()


Output: 
 

 

Value of get_gridlines() :
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7099 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS