本文整理汇总了Python中matplotlib.transforms.Transform方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.Transform方法的具体用法?Python transforms.Transform怎么用?Python transforms.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.transforms
的用法示例。
在下文中一共展示了transforms.Transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def __call__(self, renderer):
if isinstance(self._artist, Artist):
bbox = self._artist.get_window_extent(renderer)
l, b, w, h = bbox.bounds
xf, yf = self._ref_coord
x, y = l + w * xf, b + h * yf
elif isinstance(self._artist, BboxBase):
l, b, w, h = self._artist.bounds
xf, yf = self._ref_coord
x, y = l + w * xf, b + h * yf
elif isinstance(self._artist, Transform):
x, y = self._artist.transform_point(self._ref_coord)
else:
raise RuntimeError("unknown type")
sc = self._get_scale(renderer)
tr = Affine2D().scale(sc, sc).translate(x, y)
return tr
示例2: update_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def update_transform(self, aux_trans):
if isinstance(aux_trans, Transform):
def transform_xy(x, y):
x, y = np.asarray(x), np.asarray(y)
ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1)
ll2 = aux_trans.transform(ll1)
lon, lat = ll2[:,0], ll2[:,1]
return lon, lat
def inv_transform_xy(x, y):
x, y = np.asarray(x), np.asarray(y)
ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1)
ll2 = aux_trans.inverted().transform(ll1)
lon, lat = ll2[:,0], ll2[:,1]
return lon, lat
else:
transform_xy, inv_transform_xy = aux_trans
self.transform_xy = transform_xy
self.inv_transform_xy = inv_transform_xy
示例3: plt_patch
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def plt_patch(node: minidom.Element, trans_parent_trans: mtransforms.Transform, style: dict, constructor: callable, ids: dict, no_draw: bool = False) -> mpatches.Patch:
""" add a node to the figure by calling the provided constructor """
trans_node = parseTransformation(node.getAttribute("transform"))
style = get_inline_style(node, get_css_style(node, ids["css"], style))
patch = constructor(node, trans_node + trans_parent_trans + plt.gca().transData, style, ids)
if not isinstance(patch, list):
patch = [patch]
for p in patch:
if not getattr(p, "is_marker", False):
style = apply_style(style, p)
p.style = style
#p.set_transform(p.get_transform() + plt.gca().transData)
p.trans_parent = trans_parent_trans
p.trans_node = parseTransformation(node.getAttribute("transform"))
if not no_draw and not styleNoDisplay(style):
plt.gca().add_patch(p)
if node.getAttribute("id") != "":
ids[node.getAttribute("id")] = patch
return patch
示例4: set_clip_path
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def set_clip_path(self, path, transform=None):
"""
Set the artist's clip path, which may be:
* a :class:`~matplotlib.patches.Patch` (or subclass) instance
* a :class:`~matplotlib.path.Path` instance, in which case
an optional :class:`~matplotlib.transforms.Transform`
instance may be provided, which will be applied to the
path before using it for clipping.
* *None*, to remove the clipping path
For efficiency, if the path happens to be an axis-aligned
rectangle, this method will set the clipping box to the
corresponding rectangle and set the clipping path to *None*.
ACCEPTS: [ (:class:`~matplotlib.path.Path`,
:class:`~matplotlib.transforms.Transform`) |
:class:`~matplotlib.patches.Patch` | None ]
"""
super(Text, self).set_clip_path(path, transform)
self._update_clip_properties()
示例5: update_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def update_transform(self, aux_trans):
if isinstance(aux_trans, Transform):
def transform_xy(x, y):
ll1 = np.column_stack([x, y])
ll2 = aux_trans.transform(ll1)
lon, lat = ll2[:,0], ll2[:,1]
return lon, lat
def inv_transform_xy(x, y):
ll1 = np.column_stack([x, y])
ll2 = aux_trans.inverted().transform(ll1)
lon, lat = ll2[:,0], ll2[:,1]
return lon, lat
else:
transform_xy, inv_transform_xy = aux_trans
self.transform_xy = transform_xy
self.inv_transform_xy = inv_transform_xy
示例6: update_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def update_transform(self, aux_trans):
if isinstance(aux_trans, Transform):
def transform_xy(x, y):
ll1 = np.column_stack([x, y])
ll2 = aux_trans.transform(ll1)
lon, lat = ll2[:, 0], ll2[:, 1]
return lon, lat
def inv_transform_xy(x, y):
ll1 = np.column_stack([x, y])
ll2 = aux_trans.inverted().transform(ll1)
lon, lat = ll2[:, 0], ll2[:, 1]
return lon, lat
else:
transform_xy, inv_transform_xy = aux_trans
self.transform_xy = transform_xy
self.inv_transform_xy = inv_transform_xy
示例7: transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def transform(self, input_coords):
"""
Transform one set of coordinates to another
"""
if self.same_frames:
return input_coords
input_coords = input_coords*u.deg
x_in, y_in = input_coords[:, 0], input_coords[:, 1]
c_in = SkyCoord(UnitSphericalRepresentation(x_in, y_in),
frame=self.input_system)
# We often need to transform arrays that contain NaN values, and filtering
# out the NaN values would have a performance hit, so instead we just pass
# on all values and just ignore Numpy warnings
with np.errstate(all='ignore'):
c_out = c_in.transform_to(self.output_system)
lon = c_out.spherical.lon.deg
lat = c_out.spherical.lat.deg
return np.concatenate((lon[:, np.newaxis], lat[:, np.newaxis]), axis=1)
示例8: set_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def set_transform(self, t):
"""
Set the :class:`matplotlib.transforms.Transform` instance used
by this artist.
ACCEPTS: a :class:`matplotlib.transforms.Transform` instance
"""
Text.set_transform(self, t)
self.dashline.set_transform(t)
示例9: get_offset_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def get_offset_transform(self):
t = self._transOffset
if (not isinstance(t, transforms.Transform)
and hasattr(t, '_as_mpl_transform')):
t = t._as_mpl_transform(self.axes)
return t
示例10: get_transform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def get_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform`
instance used by this ContourSet.
"""
if self._transform is None:
self._transform = self.ax.transData
elif (not isinstance(self._transform, mtrans.Transform)
and hasattr(self._transform, '_as_mpl_transform')):
self._transform = self._transform._as_mpl_transform(self.ax)
return self._transform
示例11: __init__
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def __init__(self, axis=None, use_rmin=True,
_apply_theta_transforms=True):
mtransforms.Transform.__init__(self)
self._axis = axis
self._use_rmin = use_rmin
self._apply_theta_transforms = _apply_theta_transforms
示例12: deform
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def deform(base_trans: mtransforms.Transform, x: float, y: float, sx: float = 0, sy: float = 0):
""" apply an affine transformation to the given transformation """
return mtransforms.Affine2D([[x, sx, 0], [sy, y, 0], [0, 0, 1]]) + base_trans
示例13: parseTransformation
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def parseTransformation(transform_text: str) -> mtransforms.Transform:
""" convert a transform string in the svg file to a matplotlib transformation """
base_trans = mtransforms.IdentityTransform()
if transform_text is None or transform_text == "":
return base_trans
transformations_list = re.findall(r"\w*\([-.,\d\s]*\)", transform_text)
for transform_text in transformations_list:
data = [float(s) for s in re.findall(r"[-.\d]+", transform_text)]
command = re.findall(r"^\w+", transform_text)[0]
if command == "translate":
try:
ox, oy = data
except ValueError:
ox, oy = data[0], data[0]
base_trans = mtransforms.Affine2D([[1, 0, ox], [0, 1, oy], [0, 0, 1]]) + base_trans
elif command == "rotate":
a = np.deg2rad(data[0])
ca, sa = np.cos(a), np.sin(a)
base_trans = mtransforms.Affine2D([[ca, -sa, 0], [sa, ca, 0], [0, 0, 1]]) + base_trans
elif command == "scale":
if len(data) >= 2:
x, y = data
else:
x, y = data[0], data[0]
base_trans = mtransforms.Affine2D([[x, 0, 0], [0, y, 0], [0, 0, 1]]) + base_trans
elif command == "skewX":
x, = data
x = np.tan(x*np.pi/180)
base_trans = mtransforms.Affine2D([[1, x, 0], [0, 1, 0], [0, 0, 1]]) + base_trans
elif command == "skewY":
y, = data
y = np.tan(y*np.pi/180)
base_trans = mtransforms.Affine2D([[1, 0, 0], [y, 1, 0], [0, 0, 1]]) + base_trans
elif command == "matrix":
x, sy, sx, y, ox, oy = data
base_trans = mtransforms.Affine2D([[x, sx, ox], [sy, y, oy], [0, 0, 1]]) + base_trans
else:
print("ERROR: unknown transformation", transform_text)
return base_trans
示例14: patch_rect
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def patch_rect(node: minidom.Element, trans: mtransforms.Transform, style: dict, ids: dict) -> mpatches.Rectangle:
""" draw a svg rectangle node as a rectangle patch element into the figure (with the given transformation and style) """
if node.getAttribute("d") != "":
return patch_path(node, trans, style, ids)
return mpatches.Rectangle(xy=(float(node.getAttribute("x")), float(node.getAttribute("y"))),
width=float(node.getAttribute("width")),
height=float(node.getAttribute("height")),
transform=trans)
示例15: patch_ellipse
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Transform [as 别名]
def patch_ellipse(node: minidom.Element, trans: mtransforms.Transform, style: dict, ids: dict) -> mpatches.Ellipse:
""" draw a svg ellipse node as a ellipse patch element into the figure (with the given transformation and style) """
if node.getAttribute("d") != "":
return patch_path(node, trans, style, ids)
return mpatches.Ellipse(xy=(float(node.getAttribute("cx")), float(node.getAttribute("cy"))),
width=float(node.getAttribute("rx"))*2,
height=float(node.getAttribute("ry"))*2,
transform=trans)