Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。它是Python中令人惊叹的可视化库,用于数组的2D图,并用于与更广泛的SciPy堆栈配合使用。
Matplotlib.axis.Axis.set_gid()函数
matplotlib库的axis模块中的Axis.set_gid()函数用于设置艺术家的(组)ID。
用法: Axis.set_gid(self, gid)
参数:此方法接受以下参数。
- gid:此参数是作为gid给出的字符串。
返回值:此方法不返回任何值。
以下示例说明了matplotlib.axis中的matplotlib.axis.Axis.set_gid()函数:
范例1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
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):
Axis.set_gid(t, 'patch_% d' % i)
fig.suptitle('matplotlib.axis.Axis.set_gid() \
function Example\n', fontweight ="bold")
plt.show()
输出:
范例2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
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), 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 green 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):
Axis.set_gid(t, 'patch_% d'% i)
for i, t in enumerate(ax.texts):
Axis.set_gid(t, 'tooltip_% d'% i)
ax.set_xlim(-30, 30)
ax.set_ylim(-30, 30)
ax.set_aspect('equal')
fig.suptitle('matplotlib.axis.Axis.set_gid() \
function Example\n', fontweight ="bold")
plt.show()
输出:
相关用法
- Python Wand function()用法及代码示例
- Python now()用法及代码示例
- Python map()用法及代码示例
- Python ord()用法及代码示例
- Python hex()用法及代码示例
- Python tell()用法及代码示例
- Python int()用法及代码示例
- Python oct()用法及代码示例
- Python id()用法及代码示例
- Python cmp()用法及代码示例
- Python str()用法及代码示例
- Python dir()用法及代码示例
- Python sum()用法及代码示例
- Python property()用法及代码示例
- Python format()用法及代码示例
- Python range()用法及代码示例
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axis.Axis.set_gid() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。