当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Matplotlib.artist.Artist.get_gid()用法及代码示例


Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。的Artist类包含呈现对象的Abstract基类到一个FigureCanvas中。图中所有可见元素都是Artist的子类。

Matplotlib.artist.Artist.get_gid()方法

matplotlib库的艺术家模块中的get_gid()方法用于获取组ID。

用法:
艺术家.get_gid(self)

参数:此方法不接受任何参数。

返回值:此方法返回组ID。

以下示例说明了matplotlib.artist.Artist.get_gid()在matplotlib中的函数:

范例1:



# Implementation of matplotlib function 
from matplotlib.artist import Artist  
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):  
    Artist.set_gid(t, 'patch_% d' % i) 
    print("Value Return:", Artist.get_gid(t)) 
  
fig.suptitle("""matplotlib.artist.Artist.get_gid() 
function Example""", fontweight="bold") 
  
plt.show()

输出:

Value Return:patch_ 0

范例2:

# Implementation of matplotlib function 
from 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),  
            )  
  
print("Value Return:")  
for i, t in enumerate(ax.patches):  
    Artist.set_gid(t, 'patch_% d'% i) 
    print(Artist.get_gid(t))  
    
for i, t in enumerate(ax.texts):  
    Artist.set_gid(t, 'tooltip_% d'% i) 
    print(Artist.get_gid(t))  
    
ax.set_xlim(-30, 30)  
ax.set_ylim(-30, 30)  
ax.set_aspect('equal')  
  
fig.suptitle("""matplotlib.artist.Artist.get_gid() 
function Example""", fontweight="bold") 
  
plt.show()

输出:

Value Return:
patch_ 0
patch_ 1
tooltip_ 0
tooltip_ 1



相关用法


注:本文由纯净天空筛选整理自shivanisinghss2110大神的英文原创作品 Matplotlib.artist.Artist.get_gid() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。