Friday, January 16, 2026
HomeLanguagesMatplotlib.axes.Axes.get_gid() in Python

Matplotlib.axes.Axes.get_gid() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.get_gid() Function

The Axes.get_gid() function in axes module of matplotlib library is used to get the group id.

Syntax: Axes.get_gid(self)

Parameters: This method does not accepts any parameter.

Returns: This method return the group id.

Below examples illustrate the matplotlib.axes.Axes.get_gid() function in matplotlib.axes:

Example 1:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
  
  
y, x = np.mgrid[:5, 1:6]
  
poly_coords = [
    (0.25, 2.75), (3.25, 2.75),
    (2.25, 0.75), (0.25, 0.75)
]
fig, ax = plt.subplots()
    
cells = ax.plot(x, y, x + y, color ='green')
  
ax.add_patch(
    plt.Polygon(poly_coords, color ='forestgreen',
                alpha = 0.5)
    )
ax.margins(x = 0.1, y = 0.05)
ax.set_aspect('equal')
  
for i, t in enumerate(ax.patches):
    t.set_gid('patch_% d' % i)
    print("Value Return :", t.get_gid())
    
fig.suptitle('matplotlib.axes.Axes.get_gid() function\
 Example\n\n', fontweight ="bold")
  
plt.show()


Output:

Value Return : patch_0

Example 2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
  
  
fig, ax = plt.subplots()
   
circle = plt.Circle((0, 0), 5, fc ='blue')
rect = plt.Rectangle((-5, 10), 10, 5, fc ='green')
   
ax.add_patch(circle)
ax.add_patch(rect)
   
circle_tip = ax.annotate('This is a blue circle.',
            xy =(0, 0),
            xytext =(30, -30),
            textcoords ='offset points',
            color ='w',
            ha ='left',
            bbox = dict(boxstyle ='round, pad =.5'
                        fc =(.1, .1, .1, .92), 
                        ec =(1., 1., 1.), 
                        lw = 1,
                        zorder = 1),
            )
   
rect_tip = ax.annotate('This is a green rectangle.',
            xy =(-5, 10),
            xytext =(30, 40),
            textcoords ='offset points',
            color ='w',
            ha ='left',
            bbox = dict(boxstyle ='round, pad =.5'
                        fc =(.1, .1, .1, .92), 
                        ec =(1., 1., 1.), 
                        lw = 1,
                        zorder = 1),
            )
print("Value Return")
for i, t in enumerate(ax.patches):
    t.set_gid('patch_% d'% i)
    print(t.get_gid())
  
for i, t in enumerate(ax.texts):
    t.set_gid('tooltip_% d'% i)
    print(t.get_gid())
  
ax.set_xlim(-30, 30)
ax.set_ylim(-30, 30)
ax.set_aspect('equal')
    
fig.suptitle('matplotlib.axes.Axes.get_gid() function\
Example\n\n', fontweight ="bold")
  
plt.show()


Output:

Value Return
patch_0
patch_1
tooltip_0
tooltip_1
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32470 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6838 POSTS0 COMMENTS
Nicole Veronica
11972 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12055 POSTS0 COMMENTS
Shaida Kate Naidoo
6975 POSTS0 COMMENTS
Ted Musemwa
7214 POSTS0 COMMENTS
Thapelo Manthata
6928 POSTS0 COMMENTS
Umr Jansen
6906 POSTS0 COMMENTS