当前位置: 首页>>代码示例>>Python>>正文


Python Bbox.union方法代码示例

本文整理汇总了Python中matplotlib.transforms.Bbox.union方法的典型用法代码示例。如果您正苦于以下问题:Python Bbox.union方法的具体用法?Python Bbox.union怎么用?Python Bbox.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.transforms.Bbox的用法示例。


在下文中一共展示了Bbox.union方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tight_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
def get_tight_bbox(fig, bbox_extra_artists=[], pad=None):
    """
    Compute a tight bounding box around all the artists in the figure.
    """
    renderer = fig.canvas.get_renderer()
    bbox_inches = fig.get_tightbbox(renderer)
    bbox_artists = bbox_extra_artists[:]
    bbox_artists += fig.get_default_bbox_extra_artists()
    bbox_filtered = []
    for a in bbox_artists:
        bbox = a.get_window_extent(renderer)
        if isinstance(bbox, tuple):
            continue
        if a.get_clip_on():
            clip_box = a.get_clip_box()
            if clip_box is not None:
                bbox = Bbox.intersection(bbox, clip_box)
            clip_path = a.get_clip_path()
            if clip_path is not None and bbox is not None:
                clip_path = clip_path.get_fully_transformed_path()
                bbox = Bbox.intersection(bbox,
                                         clip_path.get_extents())
        if bbox is not None and (bbox.width != 0 or
                                 bbox.height != 0):
            bbox_filtered.append(bbox)
    if bbox_filtered:
        _bbox = Bbox.union(bbox_filtered)
        trans = Affine2D().scale(1.0 / fig.dpi)
        bbox_extra = TransformedBbox(_bbox, trans)
        bbox_inches = Bbox.union([bbox_inches, bbox_extra])
    return bbox_inches.padded(pad) if pad else bbox_inches
开发者ID:basnijholt,项目名称:holoviews,代码行数:33,代码来源:util.py

示例2: _compute_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def _compute_bbox(self, fig, kw):
        """
        Compute the tight bounding box for each figure once, reducing
        number of required canvas draw calls from N*2 to N+1 as a
        function of the number of frames.

        Tight bounding box computing code here mirrors:
        matplotlib.backend_bases.FigureCanvasBase.print_figure
        as it hasn't been factored out as a function.
        """
        fig_id = id(fig)
        if kw['bbox_inches'] == 'tight':
            if not fig_id in MPLRenderer.drawn:
                fig.set_dpi(self.dpi)
                fig.canvas.draw()
                renderer = fig._cachedRenderer
                bbox_inches = fig.get_tightbbox(renderer)
                bbox_artists = kw.pop("bbox_extra_artists", [])
                bbox_artists += fig.get_default_bbox_extra_artists()
                bbox_filtered = []
                for a in bbox_artists:
                    bbox = a.get_window_extent(renderer)
                    if isinstance(bbox, tuple):
                        continue
                    if a.get_clip_on():
                        clip_box = a.get_clip_box()
                        if clip_box is not None:
                            bbox = Bbox.intersection(bbox, clip_box)
                        clip_path = a.get_clip_path()
                        if clip_path is not None and bbox is not None:
                            clip_path = clip_path.get_fully_transformed_path()
                            bbox = Bbox.intersection(bbox,
                                                     clip_path.get_extents())
                    if bbox is not None and (bbox.width != 0 or
                                             bbox.height != 0):
                        bbox_filtered.append(bbox)
                if bbox_filtered:
                    _bbox = Bbox.union(bbox_filtered)
                    trans = Affine2D().scale(1.0 / self.dpi)
                    bbox_extra = TransformedBbox(_bbox, trans)
                    bbox_inches = Bbox.union([bbox_inches, bbox_extra])
                pad = plt.rcParams['savefig.pad_inches']
                bbox_inches = bbox_inches.padded(pad)
                MPLRenderer.drawn[fig_id] = bbox_inches
                kw['bbox_inches'] = bbox_inches
            else:
                kw['bbox_inches'] = MPLRenderer.drawn[fig_id]
        return kw
开发者ID:RafalSkolasinski,项目名称:holoviews,代码行数:50,代码来源:renderer.py

示例3: draw

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
 def draw(self, renderer, *args, **kwargs):
     bbox = Bbox.union(self.yaxes.get_ticklabel_extents(
         renderer).broadcast('__getitem__')(0))
     x = bbox.xmin - self.labelpad * self.get_figure().dpi / 72.0
     y = (bbox.ymin + bbox.ymax) / 2.0
     self.label.set_position((x, y))
     self.label.draw(renderer, *args, **kwargs)
开发者ID:jgosmann,项目名称:neat-plots,代码行数:9,代码来源:tools.py

示例4: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def get_tightbbox(self, renderer, call_axes_locator=True):

        bb0 = super(Axes, self).get_tightbbox(renderer, call_axes_locator)

        if not self._axisline_on:
            return bb0

        bb = [bb0]

        for axisline in self._axislines.values():
            if not axisline.get_visible():
                continue

            bb.append(axisline.get_tightbbox(renderer))
            # if axisline.label.get_visible():
            #     bb.append(axisline.label.get_window_extent(renderer))


            # if axisline.major_ticklabels.get_visible():
            #     bb.extend(axisline.major_ticklabels.get_window_extents(renderer))
            # if axisline.minor_ticklabels.get_visible():
            #     bb.extend(axisline.minor_ticklabels.get_window_extents(renderer))
            # if axisline.major_ticklabels.get_visible() or \
            #    axisline.minor_ticklabels.get_visible():
            #     bb.append(axisline.offsetText.get_window_extent(renderer))

        #bb.extend([c.get_window_extent(renderer) for c in artists \
        #           if c.get_visible()])

        _bbox = Bbox.union([b for b in bb if b and (b.width!=0 or b.height!=0)])

        return _bbox
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:34,代码来源:axislines.py

示例5: png_response

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def png_response(self):

        # try:
        #     self.set_ylim_margin(top=0.1, bottom=0.0)
        # except:
        #     pass
        # self.set_ylim_margin(top=0.1, bottom=0.0)

        major_locator = LessTicksAutoDateLocator(tz=self.tz)
        self.axes.xaxis.set_major_locator(major_locator)

        major_formatter = MultilineAutoDateFormatter(major_locator, self.axes, self.tz)
        self.axes.xaxis.set_major_formatter(major_formatter)

        # Do final tweaks after data has been added to the axes
        # ylim_old = self.axes.get_ylim()
        # ylim_new = (ylim_old[0],
        #             ylim_old[1] + 0.15 * (ylim_old[1] - ylim_old[0]))
        # self.axes.set_ylim(ylim_new)

        # self.legend()
        self.axes.set_xlim(date2num((self.start_date_ams, self.end_date_ams)))

        # find out about the data extents and set ylim accordingly
        if len(self.axes.patches) > 0:
            data_bbox = Bbox.union([p.get_extents() for p in self.axes.patches])
            ymin, ymax = data_bbox.inverse_transformed(self.axes.transData).get_points()[:, 1] * array([1, 1.1])
            ymax = max(1, ymax)
            ymin = -0.01 * ymax

            self.axes.set_ylim((ymin, ymax))

        return super(RainappGraph, self).png_response()
开发者ID:nens,项目名称:nens-graph,代码行数:35,代码来源:rainapp.py

示例6: test_text_with_arrow_annotation_get_window_extent

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
def test_text_with_arrow_annotation_get_window_extent():
    headwidth = 21
    fig, ax = plt.subplots(dpi=100)
    txt = ax.text(s='test', x=0, y=0)
    ann = ax.annotate(
        'test',
        xy=(0.0, 50.0),
        xytext=(50.0, 50.0), xycoords='figure pixels',
        arrowprops={
            'facecolor': 'black', 'width': 2,
            'headwidth': headwidth, 'shrink': 0.0})

    plt.draw()
    renderer = fig.canvas.renderer
    # bounding box of text
    text_bbox = txt.get_window_extent(renderer=renderer)
    # bounding box of annotation (text + arrow)
    bbox = ann.get_window_extent(renderer=renderer)
    # bounding box of arrow
    arrow_bbox = ann.arrow.get_window_extent(renderer)
    # bounding box of annotation text
    ann_txt_bbox = Text.get_window_extent(ann)

    # make sure annotation with in 50 px wider than
    # just the text
    eq_(bbox.width, text_bbox.width + 50.0)
    # make sure the annotation text bounding box is same size
    # as the bounding box of the same string as a Text object
    eq_(ann_txt_bbox.height, text_bbox.height)
    eq_(ann_txt_bbox.width, text_bbox.width)
    # compute the expected bounding box of arrow + text
    expected_bbox = Bbox.union([ann_txt_bbox, arrow_bbox])
    assert_almost_equal(bbox.height, expected_bbox.height)
开发者ID:AndreLobato,项目名称:matplotlib,代码行数:35,代码来源:test_text.py

示例7: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def get_tightbbox(self, renderer):
        if not self.get_visible():
            return

        self._axis_artist_helper.update_lim(self.axes)

        dpi_cor = renderer.points_to_pixels(1.)
        self.dpi_transform.clear().scale(dpi_cor, dpi_cor)

        bb = []

        self._update_ticks(renderer)

        bb.extend(self.major_ticklabels.get_window_extents(renderer))
        bb.extend(self.minor_ticklabels.get_window_extents(renderer))

        self._update_label(renderer)

        bb.append(self.label.get_window_extent(renderer))
        bb.append(self.offsetText.get_window_extent(renderer))

        bb = [b for b in bb if b and (b.width != 0 or b.height != 0)]
        if bb:
            _bbox = Bbox.union(bb)
            return _bbox
        else:
            return None
开发者ID:HubertHolin,项目名称:matplotlib,代码行数:29,代码来源:axis_artist.py

示例8: zoom_nodes

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def zoom_nodes(self, nodes, border=1.2):
        y0, y1 = self.get_ylim(); x0, x1 = self.get_xlim()
        y0 = max(0, y0); y1 = min(1, y1)

        n2c = self.n2c
        v = [ n2c[n] for n in nodes ]
        ymin = min([ c.y for c in v ])
        ymax = max([ c.y for c in v ])
        xmin = min([ c.x for c in v ])
        xmax = max([ c.x for c in v ])
        bb = Bbox(((xmin,ymin), (xmax, ymax)))

        # convert data coordinates to display coordinates
        transform = self.transData.transform
        disp_bb = [Bbox(transform(bb))]
        for n in nodes:
            if n.isleaf:
                txt = self.node2label[n]
                if txt.get_visible():
                    disp_bb.append(txt.get_window_extent())

        disp_bb = Bbox.union(disp_bb).expanded(border, border)

        # convert back to data coordinates
        points = self.transData.inverted().transform(disp_bb)
        x0, x1 = points[:,0]
        y0, y1 = points[:,1]
        self.set_xlim(x0, x1)
        self.set_ylim(y0, y1)
开发者ID:OpenTreeOfLife,项目名称:phylografter,代码行数:31,代码来源:matplot.py

示例9: zoom_nodes

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def zoom_nodes(self, nodes, border=1.2):
        y0, y1 = self.get_ylim(); x0, x1 = self.get_xlim()
        y0 = max(0, y0); y1 = min(1, y1)

        n2c = self.n2c
        v = [ n2c[n] for n in nodes ]
        ymin = min([ c.y for c in v ])
        ymax = max([ c.y for c in v ])
        xmin = min([ c.x for c in v ])
        xmax = max([ c.x for c in v ])
        bb = Bbox(((xmin,ymin), (xmax, ymax)))

        # convert data coordinates to display coordinates
        transform = self.transData.transform
        disp_bb = [Bbox(transform(bb))]


        disp_bb = Bbox.union(disp_bb).expanded(border, border)

        # convert back to data coordinates
        points = self.transData.inverted().transform(disp_bb)
        x0, x1 = points[:,0]
        y0, y1 = points[:,1]
        self.set_xlim(x0, x1)
        self.set_ylim(y0, y1)
        self.draw_labels()
开发者ID:ChriZiegler,项目名称:ivy,代码行数:28,代码来源:treevis.py

示例10: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
 def get_tightbbox(self, renderer, call_axes_locator=True,
                   bbox_extra_artists=None):
     bbs = [ax.get_tightbbox(renderer, call_axes_locator=call_axes_locator)
            for ax in self.parasites]
     bbs.append(super().get_tightbbox(renderer,
             call_axes_locator=call_axes_locator,
             bbox_extra_artists=bbox_extra_artists))
     return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])
开发者ID:mattip,项目名称:matplotlib,代码行数:10,代码来源:parasite_axes.py

示例11: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def get_tightbbox(self, renderer):

        bbs = [ax.get_tightbbox(renderer) for ax in self.parasites]
        bbs.append(super(HostAxes, self).get_tightbbox(renderer))

        _bbox = Bbox.union([b for b in bbs if b.width!=0 or b.height!=0])

        return _bbox
开发者ID:,项目名称:,代码行数:10,代码来源:

示例12: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
    def get_tightbbox(self, renderer):

        bbs = [ax.get_tightbbox(renderer) for ax in self.parasites]
        get_tightbbox = self._get_base_axes_attr("get_tightbbox")
        bbs.append(get_tightbbox(self, renderer))

        _bbox = Bbox.union([b for b in bbs if b.width!=0 or b.height!=0])

        return _bbox
开发者ID:MariaNattestad,项目名称:clonal-deconvolution-from-copy-number,代码行数:11,代码来源:parasite_axes.py

示例13: get_tightbbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
 def get_tightbbox(self, renderer, call_axes_locator=True):
     bb0 = super().get_tightbbox(renderer, call_axes_locator)
     if not self._axisline_on:
         return bb0
     bb = [bb0] + [axisline.get_tightbbox(renderer)
                   for axisline in self._axislines.values()
                   if axisline.get_visible()]
     bbox = Bbox.union([b for b in bb if b and (b.width!=0 or b.height!=0)])
     return bbox
开发者ID:magnunor,项目名称:matplotlib,代码行数:11,代码来源:axislines.py

示例14: _calculate_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
 def _calculate_bbox(self):
     r = self.renderer
     bboxes = self.xaxis.get_window_extent(r), self.yaxis.get_window_extent(r), self.subplot.bbox
     all_bbox = Bbox.union(bboxes)
     (x0, y0), (x1, y1) = all_bbox.get_points()
     w = x1 - x0
     h = y1 - y0
     all_bbox = Bbox.from_bounds(x0, y0, w * 1.02, h * 1.02)
     return all_bbox
开发者ID:nitetrain8,项目名称:pysrc2,代码行数:11,代码来源:plotwidget.py

示例15: composite_images

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import union [as 别名]
def composite_images(images, renderer, magnification=1.0):
    """
    Composite a number of RGBA images into one.  The images are
    composited in the order in which they appear in the `images` list.

    Parameters
    ----------
    images : list of Images
        Each must have a `make_image` method.  For each image,
        `can_composite` should return `True`, though this is not
        enforced by this function.  Each image must have a purely
        affine transformation with no shear.

    renderer : RendererBase instance

    magnification : float
        The additional magnification to apply for the renderer in use.

    Returns
    -------
    tuple : image, offset_x, offset_y
        Returns the tuple:

        - image: A numpy array of the same type as the input images.

        - offset_x, offset_y: The offset of the image (left, bottom)
          in the output figure.
    """
    if len(images) == 0:
        return np.empty((0, 0, 4), dtype=np.uint8), 0, 0

    parts = []
    bboxes = []
    for image in images:
        data, x, y, trans = image.make_image(renderer, magnification)
        if data is not None:
            x *= magnification
            y *= magnification
            parts.append((data, x, y, image.get_alpha() or 1.0))
            bboxes.append(
                Bbox([[x, y], [x + data.shape[1], y + data.shape[0]]]))

    if len(parts) == 0:
        return np.empty((0, 0, 4), dtype=np.uint8), 0, 0

    bbox = Bbox.union(bboxes)

    output = np.zeros(
        (int(bbox.height), int(bbox.width), 4), dtype=np.uint8)

    for data, x, y, alpha in parts:
        trans = Affine2D().translate(x - bbox.x0, y - bbox.y0)
        _image.resample(data, output, trans, _image.NEAREST,
                        resample=False, alpha=alpha)

    return output, bbox.x0 / magnification, bbox.y0 / magnification
开发者ID:Perados,项目名称:matplotlib,代码行数:58,代码来源:image.py


注:本文中的matplotlib.transforms.Bbox.union方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。