Matplotlib.artist.Artist.set_gid() in Python - GeeksforGeeks

15 May, 2020
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Artist class contains Abstract base class for objects that render into a FigureCanvas. All visible elements in a figure are subclasses of Artist.
The set_gid() method in artist module of matplotlib library is used to set the (group) id for the artist.
Syntax: Artist.set_gid(self, gid)
Parameters: This method accepts only one parameters.
gid: This parameter is the string given as gid.
Returns: This method does not return any value.
Below examples illustrate the matplotlib.artist.Artist.set_gid() function in matplotlib:
Example 1:
# Implementation of matplotlib functionfrom matplotlib.artist import Artistimport numpy as npimport 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):    Artist.set_gid(t, 'patch_% d' % i)  fig.suptitle("""matplotlib.artist.Artist.set_gid()function Example""", fontweight="bold")  plt.show()
Output:
Example 2:
# Implementation of matplotlib functionfrom matplotlib.artist import Artist 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),             )     for i, t in enumerate(ax.patches):     Artist.set_gid(t, 'patch_% d'% i)     for i, t in enumerate(ax.texts):     Artist.set_gid(t, 'tooltip_% d'% i)     ax.set_xlim(-30, 30) ax.set_ylim(-30, 30) ax.set_aspect('equal')   fig.suptitle("""matplotlib.artist.Artist.set_gid()function Example""", fontweight="bold")  plt.show()
Output:
Matplotlib Artist-class
Python-matplotlib
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
How to Install PIP on Windows ?
Read a file line by line in Python
Enumerate() in Python
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python program to convert a list to string
Create a Pandas DataFrame from Lists
Python String | replace()
Reading and Writing to text files in Python