Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。
matplotlib.axes.Axes.get_transform()函数
matplotlib库的axes模块中的Axes.get_transform()函数用于获取该艺术家使用的Transform实例
用法: Axes.get_transform(self)
参数:此方法不接受任何参数。
返回:此方法返回该艺术家使用的Transform实例
以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.get_transform()函数:
范例1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
fig, ax = plt.subplots()
l1, = ax.plot([0.1, 0.5, 0.9], [0.1, 0.9, 0.5], "bo-")
l2, = ax.plot([0.1, 0.5, 0.9], [0.5, 0.2, 0.7], "ro-")
for l in [l1, l2]:
xx = l.get_xdata()
yy = l.get_ydata()
shadow, = ax.plot(xx, yy)
shadow.update_from(l)
ot = mtransforms.offset_copy(l.get_transform(),
ax.figure,
x = 4.0, y =-6.0,
units ='points')
shadow.set_transform(ot)
fig.suptitle('matplotlib.axes.Axes.get_transform() \
function Example', fontweight ="bold")
plt.show()
输出:
范例2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib import collections, colors, transforms
import numpy as np
nverts = 50
npts = 100
r = np.arange(nverts)
theta = np.linspace(0, 2 * np.pi, nverts)
xx = r * np.sin(theta)
yy = r * np.cos(theta)
spiral = np.column_stack([xx, yy])
rs = np.random.RandomState(19680801)
xyo = rs.randn(npts, 2)
colors = [colors.to_rgba(c)
for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]
fig, ax1 = plt.subplots()
col = collections.RegularPolyCollection(
7, sizes = np.abs(xx) * 10.0,
offsets = xyo,
transOffset = ax1.transData)
trans = transforms.Affine2D().scale(fig.dpi / 72.0)
col.set_transform(trans)
ax1.add_collection(col, autolim = True)
col.set_color(colors)
print("Value Return by get_transform():\n",
col.get_transform())
fig.suptitle('matplotlib.axes.Axes.get_transform() \
function Example', fontweight ="bold")
plt.show()
输出:
Value Return by get_transform(): Affine2D( [[1.38888889 0. 0. ] [0. 1.38888889 0. ] [0. 0. 1. ]])
相关用法
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axes.Axes.get_transform() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。