本文整理汇总了Python中matplotlib.transforms.Bbox方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.Bbox方法的具体用法?Python transforms.Bbox怎么用?Python transforms.Bbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.transforms
的用法示例。
在下文中一共展示了transforms.Bbox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def __init__(self, meshWidth, meshHeight, coordinates,
antialiased=True, shading='flat', **kwargs):
Collection.__init__(self, **kwargs)
self._meshWidth = meshWidth
self._meshHeight = meshHeight
self._coordinates = coordinates
self._antialiased = antialiased
self._shading = shading
self._bbox = transforms.Bbox.unit()
self._bbox.update_from_data_xy(coordinates.reshape(
((meshWidth + 1) * (meshHeight + 1), 2)))
# By converting to floats now, we can avoid that on every draw.
self._coordinates = self._coordinates.reshape(
(meshHeight + 1, meshWidth + 1, 2))
self._coordinates = np.array(self._coordinates, np.float_)
示例2: set_figure
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [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()
示例3: get_position
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def get_position(self, original=False):
"""
Get a copy of the axes rectangle as a `.Bbox`.
Parameters
----------
original : bool
If ``True``, return the original position. Otherwise return the
active position. For an explanation of the positions see
`.set_position`.
Returns
-------
pos : `.Bbox`
"""
if original:
return self._originalPosition.frozen()
else:
locator = self.get_axes_locator()
if not locator:
self.apply_aspect()
return self._position.frozen()
示例4: set_figure
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [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()
示例5: relim
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def relim(self, visible_only=False):
"""
Recompute the data limits based on current artists. If you want to
exclude invisible artists from the calculation, set
``visible_only=True``
At present, :class:`~matplotlib.collections.Collection`
instances are not supported.
"""
# Collections are deliberately not supported (yet); see
# the TODO note in artists.py.
self.dataLim.ignore(True)
self.dataLim.set_points(mtransforms.Bbox.null().get_points())
self.ignore_existing_data_limits = True
for line in self.lines:
if not visible_only or line.get_visible():
self._update_line_limits(line)
for p in self.patches:
if not visible_only or p.get_visible():
self._update_patch_limits(p)
示例6: set_position
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def set_position(self, pos, which='both'):
"""
Set the axes position.
Axes have two position attributes. The 'original' position is the
position allocated for the Axes. The 'active' position is the
position the Axes is actually drawn at. These positions are usually
the same unless a fixed aspect is set to the Axes. See `.set_aspect`
for details.
Parameters
----------
pos : [left, bottom, width, height] or `~matplotlib.transforms.Bbox`
The new position of the in `.Figure` coordinates.
which : {'both', 'active', 'original'}, optional
Determines which position variables to change.
"""
self._set_position(pos, which='both')
# because this is being called externally to the library we
# zero the constrained layout parts.
self._layoutbox = None
self._poslayoutbox = None
示例7: set_position
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def set_position(self, pos, which='both'):
"""
Set the axes position.
Axes have two position attributes. The 'original' position is the
position allocated for the Axes. The 'active' position is the
position the Axes is actually drawn at. These positions are usually
the same unless a fixed aspect is set to the Axes. See `.set_aspect`
for details.
Parameters
----------
pos : [left, bottom, width, height] or `~matplotlib.transforms.Bbox`
The new position of the in `.Figure` coordinates.
which : {'both', 'active', 'original'}, optional
Determines which position variables to change.
"""
self._set_position(pos, which=which)
# because this is being called externally to the library we
# zero the constrained layout parts.
self._layoutbox = None
self._poslayoutbox = None
示例8: test_bbox_intersection
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def test_bbox_intersection():
bbox_from_ext = mtransforms.Bbox.from_extents
inter = mtransforms.Bbox.intersection
r1 = bbox_from_ext(0, 0, 1, 1)
r2 = bbox_from_ext(0.5, 0.5, 1.5, 1.5)
r3 = bbox_from_ext(0.5, 0, 0.75, 0.75)
r4 = bbox_from_ext(0.5, 1.5, 1, 2.5)
r5 = bbox_from_ext(1, 1, 2, 2)
# self intersection -> no change
assert_bbox_eq(inter(r1, r1), r1)
# simple intersection
assert_bbox_eq(inter(r1, r2), bbox_from_ext(0.5, 0.5, 1, 1))
# r3 contains r2
assert_bbox_eq(inter(r1, r3), r3)
# no intersection
assert inter(r1, r4) is None
# single point
assert_bbox_eq(inter(r1, r5), bbox_from_ext(1, 1, 1, 1))
示例9: test_bbox_image_inverted
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def test_bbox_image_inverted():
# This is just used to produce an image to feed to BboxImage
image = np.arange(100).reshape((10, 10))
fig, ax = plt.subplots()
bbox_im = BboxImage(
TransformedBbox(Bbox([[100, 100], [0, 0]]), ax.transData))
bbox_im.set_data(image)
bbox_im.set_clip_on(False)
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.add_artist(bbox_im)
image = np.identity(10)
bbox_im = BboxImage(TransformedBbox(Bbox([[0.1, 0.2], [0.3, 0.25]]),
ax.figure.transFigure))
bbox_im.set_data(image)
bbox_im.set_clip_on(False)
ax.add_artist(bbox_im)
示例10: imagesAsTickMarks
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def imagesAsTickMarks(ax, images):
TICKYPOS = -.6
lowerCorner = ax.transData.transform((.8,TICKYPOS-.2))
upperCorner = ax.transData.transform((1.2,TICKYPOS+.2))
print(lowerCorner)
print(upperCorner)
bbox_image = BboxImage(Bbox([lowerCorner[0],
lowerCorner[1],
upperCorner[0],
upperCorner[1],
]),
norm = None,
origin=None,
clip_on=False,
)
image = imread(images[0])
print('img loaded')
bbox_image.set_data(image)
ax.add_artist(bbox_image)
示例11: get_datalim
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def get_datalim(self, transData):
transform = self.get_transform()
transOffset = self.get_offset_transform()
offsets = self._offsets
paths = self.get_paths()
if not transform.is_affine:
paths = [transform.transform_path_non_affine(p) for p in paths]
transform = transform.get_affine()
if not transOffset.is_affine:
offsets = transOffset.transform_non_affine(offsets)
transOffset = transOffset.get_affine()
offsets = np.asanyarray(offsets, np.float_)
if np.ma.isMaskedArray(offsets):
offsets = offsets.filled(np.nan)
# get_path_collection_extents handles nan but not masked arrays
offsets.shape = (-1, 2) # Make it Nx2
if paths:
result = mpath.get_path_collection_extents(
transform.frozen(), paths, self.get_transforms(),
offsets, transOffset.frozen())
result = result.inverse_transformed(transData)
else:
result = transforms.Bbox([[0, 0], [0, 0]])
return result
示例12: on_draw_event
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def on_draw_event(self, widget, ctx):
""" GtkDrawable draw event, like expose_event in GTK 2.X
"""
allocation = self.get_allocation()
w, h = allocation.width, allocation.height
if not len(self._bbox_queue):
if self._need_redraw:
self._render_figure(w, h)
bbox_queue = [transforms.Bbox([[0, 0], [w, h]])]
else:
return
else:
bbox_queue = self._bbox_queue
for bbox in bbox_queue:
area = self.copy_from_bbox(bbox)
buf = np.fromstring(area.to_string_argb(), dtype='uint8')
x = int(bbox.x0)
y = h - int(bbox.y1)
width = int(bbox.x1) - int(bbox.x0)
height = int(bbox.y1) - int(bbox.y0)
image = cairo.ImageSurface.create_for_data(
buf, cairo.FORMAT_ARGB32, width, height)
ctx.set_source_surface(image, x, y)
ctx.paint()
if len(self._bbox_queue):
self._bbox_queue = []
return False
示例13: unit_bbox
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def unit_bbox():
box = Bbox(np.array([[0, 0], [1, 1]]))
return box
示例14: __init__
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def __init__(self, center, viewLim, originLim, **kwargs):
mtransforms.Bbox.__init__(self,
np.array([[0.0, 0.0], [1.0, 1.0]], np.float),
**kwargs)
self._center = center
self._viewLim = viewLim
self._originLim = originLim
self.set_children(viewLim, originLim)
示例15: on_draw_event
# 需要导入模块: from matplotlib import transforms [as 别名]
# 或者: from matplotlib.transforms import Bbox [as 别名]
def on_draw_event(self, widget, ctx):
"""GtkDrawable draw event, like expose_event in GTK 2.X.
"""
allocation = self.get_allocation()
w, h = allocation.width, allocation.height
if not len(self._bbox_queue):
Gtk.render_background(
self.get_style_context(), ctx,
allocation.x, allocation.y,
allocation.width, allocation.height)
bbox_queue = [transforms.Bbox([[0, 0], [w, h]])]
else:
bbox_queue = self._bbox_queue
ctx = backend_cairo._to_context(ctx)
for bbox in bbox_queue:
x = int(bbox.x0)
y = h - int(bbox.y1)
width = int(bbox.x1) - int(bbox.x0)
height = int(bbox.y1) - int(bbox.y0)
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
np.asarray(self.copy_from_bbox(bbox)))
image = cairo.ImageSurface.create_for_data(
buf.ravel().data, cairo.FORMAT_ARGB32, width, height)
ctx.set_source_surface(image, x, y)
ctx.paint()
if len(self._bbox_queue):
self._bbox_queue = []
return False