本文整理汇总了Python中matplotlib.transforms.TransformedBbox方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.TransformedBbox方法的具体用法?Python transforms.TransformedBbox怎么用?Python transforms.TransformedBbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.transforms
的用法示例。
在下文中一共展示了transforms.TransformedBbox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_bbox_png
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def adjust_bbox_png(fig, bbox_inches):
"""
adjust_bbox for png (Agg) format
"""
tr = fig.dpi_scale_trans
_bbox = TransformedBbox(bbox_inches,
tr)
x0, y0 = _bbox.x0, _bbox.y0
fig.bbox_inches = Bbox.from_bounds(0, 0,
bbox_inches.width,
bbox_inches.height)
x0, y0 = _bbox.x0, _bbox.y0
w1, h1 = fig.bbox.width, fig.bbox.height
fig.transFigure._boxout = Bbox.from_bounds(-x0, -y0,
w1, h1)
fig.transFigure.invalidate()
fig.bbox = TransformedBbox(fig.bbox_inches, tr)
fig.patch.set_bounds(x0 / w1, y0 / h1,
fig.bbox.width / w1, fig.bbox.height / h1)
示例2: connect_bbox
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def connect_bbox(bbox1, bbox2, loc1, loc2=None):
if isinstance(bbox1, Rectangle):
transform = bbox1.get_transfrom()
bbox1 = Bbox.from_bounds(0, 0, 1, 1)
bbox1 = TransformedBbox(bbox1, transform)
if isinstance(bbox2, Rectangle):
transform = bbox2.get_transform()
bbox2 = Bbox.from_bounds(0, 0, 1, 1)
bbox2 = TransformedBbox(bbox2, transform)
if loc2 is None:
loc2 = loc1
x1, y1 = BboxConnector.get_bbox_edge_pos(bbox1, loc1)
x2, y2 = BboxConnector.get_bbox_edge_pos(bbox2, loc2)
verts = [[x1, y1], [x2,y2]]
#Path()
codes = [Path.MOVETO, Path.LINETO]
return Path(verts, codes)
示例3: _make_secondary_locator
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def _make_secondary_locator(rect, parent):
"""
Helper function to locate the secondary axes.
A locator gets used in `Axes.set_aspect` to override the default
locations... It is a function that takes an axes object and
a renderer and tells `set_aspect` where it is to be placed.
This locator make the transform be in axes-relative co-coordinates
because that is how we specify the "location" of the secondary axes.
Here *rect* is a rectangle [l, b, w, h] that specifies the
location for the axes in the transform given by *trans* on the
*parent*.
"""
_rect = mtransforms.Bbox.from_bounds(*rect)
def secondary_locator(ax, renderer):
# delay evaluating transform until draw time because the
# parent transform may have changed (i.e. if window reesized)
bb = mtransforms.TransformedBbox(_rect, parent.transAxes)
tr = parent.figure.transFigure.inverted()
bb = mtransforms.TransformedBbox(bb, tr)
return bb
return secondary_locator
示例4: set_figure
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def set_figure(self, fig):
"""
Set the `.Figure` for this `.Axes`.
Parameters
----------
fig : `.Figure`
"""
martist.Artist.set_figure(self, fig)
self.bbox = mtransforms.TransformedBbox(self._position,
fig.transFigure)
# these will be updated later as data is added
self.dataLim = mtransforms.Bbox.null()
self.viewLim = mtransforms.Bbox.unit()
self.transScale = mtransforms.TransformWrapper(
mtransforms.IdentityTransform())
self._set_lim_and_transforms()
示例5: set_figure
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def set_figure(self, fig):
"""
Set the class:`~matplotlib.axes.Axes` figure
accepts a class:`~matplotlib.figure.Figure` instance
"""
martist.Artist.set_figure(self, fig)
self.bbox = mtransforms.TransformedBbox(self._position,
fig.transFigure)
# these will be updated later as data is added
self.dataLim = mtransforms.Bbox.null()
self.viewLim = mtransforms.Bbox.unit()
self.transScale = mtransforms.TransformWrapper(
mtransforms.IdentityTransform())
self._set_lim_and_transforms()
示例6: set_figure
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def set_figure(self, fig):
"""
Set the `.Figure` for this `.Axes`.
.. ACCEPTS: `.Figure`
Parameters
----------
fig : `.Figure`
"""
martist.Artist.set_figure(self, fig)
self.bbox = mtransforms.TransformedBbox(self._position,
fig.transFigure)
# these will be updated later as data is added
self.dataLim = mtransforms.Bbox.null()
self.viewLim = mtransforms.Bbox.unit()
self.transScale = mtransforms.TransformWrapper(
mtransforms.IdentityTransform())
self._set_lim_and_transforms()
示例7: get_bbox_to_anchor
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def get_bbox_to_anchor(self):
"""
return the bbox that the legend will be anchored
"""
if self._bbox_to_anchor is None:
return self.axes.bbox
else:
transform = self._bbox_to_anchor_transform
if transform is None:
return self._bbox_to_anchor
else:
return TransformedBbox(self._bbox_to_anchor,
transform)
示例8: set_bbox_to_anchor
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def set_bbox_to_anchor(self, bbox, transform=None):
"""
set the bbox that the legend will be anchored.
*bbox* can be a BboxBase instance, a tuple of [left, bottom,
width, height] in the given transform (normalized axes
coordinate if None), or a tuple of [left, bottom] where the
width and height will be assumed to be zero.
"""
if bbox is None:
self._bbox_to_anchor = None
return
elif isinstance(bbox, BboxBase):
self._bbox_to_anchor = bbox
else:
try:
l = len(bbox)
except TypeError:
raise ValueError("Invalid argument for bbox : %s" % str(bbox))
if l == 2:
bbox = [bbox[0], bbox[1], 0, 0]
self._bbox_to_anchor = Bbox.from_bounds(*bbox)
if transform is None:
transform = BboxTransformTo(self.parent.bbox)
self._bbox_to_anchor = TransformedBbox(self._bbox_to_anchor,
transform)
示例9: adjust_bbox_pdf
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def adjust_bbox_pdf(fig, bbox_inches):
"""
adjust_bbox for pdf & eps format
"""
if fig._cachedRenderer.__class__.__name__ == "RendererPgf":
tr = Affine2D().scale(fig.dpi)
f = 1.
else:
tr = Affine2D().scale(72)
f = 72. / fig.dpi
_bbox = TransformedBbox(bbox_inches, tr)
fig.bbox_inches = Bbox.from_bounds(0, 0,
bbox_inches.width,
bbox_inches.height)
x0, y0 = _bbox.x0, _bbox.y0
w1, h1 = fig.bbox.width * f, fig.bbox.height * f
fig.transFigure._boxout = Bbox.from_bounds(-x0, -y0,
w1, h1)
fig.transFigure.invalidate()
fig.bbox = TransformedBbox(fig.bbox_inches, tr)
fig.patch.set_bounds(x0 / w1, y0 / h1,
fig.bbox.width / w1, fig.bbox.height / h1)
示例10: __call__
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def __call__(self, ax, renderer):
fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
self._update_offset_func(renderer, fontsize)
width, height, xdescent, ydescent = self.get_extent(renderer)
px, py = self.get_offset(width, height, 0, 0, renderer)
bbox_canvas = mtrans.Bbox.from_bounds(px, py, width, height)
tr = ax.figure.transFigure.inverted()
bb = mtrans.TransformedBbox(bbox_canvas, tr)
return bb
示例11: get_extent
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def get_extent(self, renderer):
bb = mtrans.TransformedBbox(self.axes.viewLim, self.parent_axes.transData)
x, y, w, h = bb.bounds
xd, yd = 0, 0
fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
pad = self.pad * fontsize
return w*self.zoom+2*pad, h*self.zoom+2*pad, xd+pad, yd+pad
示例12: mark_inset
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
pp = BboxPatch(rect, **kwargs)
parent_axes.add_patch(pp)
p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1, **kwargs)
inset_axes.add_patch(p1)
p1.set_clip_on(False)
p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2, **kwargs)
inset_axes.add_patch(p2)
p2.set_clip_on(False)
return pp, p1, p2
示例13: set_bbox_to_anchor
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def set_bbox_to_anchor(self, bbox, transform=None):
"""
Set the bbox that the legend will be anchored to.
*bbox* can be
- A `.BboxBase` instance
- A tuple of ``(left, bottom, width, height)`` in the given transform
(normalized axes coordinate if None)
- A tuple of ``(left, bottom)`` where the width and height will be
assumed to be zero.
"""
if bbox is None:
self._bbox_to_anchor = None
return
elif isinstance(bbox, BboxBase):
self._bbox_to_anchor = bbox
else:
try:
l = len(bbox)
except TypeError:
raise ValueError("Invalid argument for bbox : %s" % str(bbox))
if l == 2:
bbox = [bbox[0], bbox[1], 0, 0]
self._bbox_to_anchor = Bbox.from_bounds(*bbox)
if transform is None:
transform = BboxTransformTo(self.parent.bbox)
self._bbox_to_anchor = TransformedBbox(self._bbox_to_anchor,
transform)
self.stale = True
示例14: _set_lim_and_transforms
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def _set_lim_and_transforms(self):
"""
Set the *_xaxis_transform*, *_yaxis_transform*, *transScale*,
*transData*, *transLimits* and *transAxes* transformations.
.. note::
This method is primarily used by rectilinear projections of the
`~matplotlib.axes.Axes` class, and is meant to be overridden by
new kinds of projection axes that need different transformations
and limits. (See `~matplotlib.projections.polar.PolarAxes` for an
example.)
"""
self.transAxes = mtransforms.BboxTransformTo(self.bbox)
# Transforms the x and y axis separately by a scale factor.
# It is assumed that this part will have non-linear components
# (e.g., for a log scale).
self.transScale = mtransforms.TransformWrapper(
mtransforms.IdentityTransform())
# An affine transformation on the data, generally to limit the
# range of the axes
self.transLimits = mtransforms.BboxTransformFrom(
mtransforms.TransformedBbox(self.viewLim, self.transScale))
# The parentheses are important for efficiency here -- they
# group the last two (which are usually affines) separately
# from the first (which, with log-scaling can be non-affine).
self.transData = self.transScale + (self.transLimits + self.transAxes)
self._xaxis_transform = mtransforms.blended_transform_factory(
self.transData, self.transAxes)
self._yaxis_transform = mtransforms.blended_transform_factory(
self.transAxes, self.transData)
示例15: mark_inset
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import TransformedBbox [as 别名]
def mark_inset(parent_axes: Axes, inset_axes: Axes, loc1: Union[int, Sequence[int]] = 1, loc2: Union[int, Sequence[int]] = 2, **kwargs):
""" like the mark_inset function from matplotlib, but loc can also be a tuple """
from mpl_toolkits.axes_grid1.inset_locator import TransformedBbox, BboxPatch, BboxConnector
try:
loc1a, loc1b = loc1
except:
loc1a = loc1
loc1b = loc1
try:
loc2a, loc2b = loc2
except:
loc2a = loc2
loc2b = loc2
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
pp = BboxPatch(rect, fill=False, **kwargs)
parent_axes.add_patch(pp)
pp.set_clip_on(False)
p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, **kwargs)
inset_axes.add_patch(p1)
p1.set_clip_on(False)
p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, **kwargs)
inset_axes.add_patch(p2)
p2.set_clip_on(False)
return pp, p1, p2