Skip to content
Related Articles

Related Articles

Matplotlib.axis.Tick.set_gid() function in Python
  • Last Updated : 10 Jun, 2020

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.Tick.set_gid() Function

The Tick.set_gid() function in axis module of matplotlib library is used to set the (group) id for the artist. 
 

Syntax: Tick.set_gid(self, gid) 
 

Parameters: This method accepts the following parameters. 

  • gid: This parameter is the string given as gid.

Return value: This method does not return any value. 



Below examples illustrate the matplotlib.axis.Tick.set_gid() function in matplotlib.axis:
Example 1:

Python3




# Implementation of matplotlib function
from matplotlib.axis import Tick
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='red'
ax.add_patch( 
    plt.Polygon(poly_coords, 
                color='lightblue'
                alpha=0.5
     
ax.margins(x=0.1, y=0.05
ax.set_aspect('equal'
     
for i, t in enumerate(ax.patches): 
    Tick.set_gid(t, 'patch_% d' % i) 
  
fig.suptitle('matplotlib.axis.Tick.set_gid() \
function Example', fontweight ="bold")  
     
plt.show() 

Output: 

Example 2:

Python3




# Implementation of matplotlib function
from matplotlib.axis import Tick
import numpy as np  
import matplotlib.pyplot as plt  
       
        
fig, ax = plt.subplots()  
       
circle = plt.Circle((0, 0), 5, fc ='lightgreen')  
rect = plt.Rectangle((-5, 10), 10, 5, fc ='red')  
       
ax.add_patch(circle)  
ax.add_patch(rect)  
       
circle_tip = ax.annotate('This is a green circle.',  
        xy =(0, 0),xytext =(30, -30), ha ='left',
        textcoords ='offset points',color ='w',
        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 red rectangle.',  
        xy =(-5, 10), xytext =(30, 40),color ='w'
        textcoords ='offset points', ha ='left',  
        bbox = dict(boxstyle ='round, pad =.5',  
            fc =(.1, .1, .1, .92), ec =(1., 1., 1.),
            lw = 1, zorder = 1))  
       
for i, t in enumerate(ax.patches):  
    Tick.set_gid(t, 'patch_% d'% i)  
       
for i, t in enumerate(ax.texts):  
    Tick.set_gid(t, 'tooltip_% d'% i)  
       
ax.set_xlim(-30, 30)  
ax.set_ylim(-30, 30)  
ax.set_aspect('equal'
  
fig.suptitle('matplotlib.axis.Tick.set_gid() \
function Example', fontweight ="bold")  
     
plt.show() 

Output: 
 

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :