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


Python Bbox.from_bounds方法代码示例

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


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

示例1: _find_best_position

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def _find_best_position(self, width, height, renderer, consider=None):
        """
        Determine the best location to place the legend.

        `consider` is a list of (x, y) pairs to consider as a potential
        lower-left corner of the legend. All are display coords.
        """
        # should always hold because function is only called internally
        assert self.isaxes

        verts, bboxes, lines, offsets = self._auto_legend_data()

        bbox = Bbox.from_bounds(0, 0, width, height)
        if consider is None:
            consider = [self._get_anchored_bbox(x, bbox,
                                                self.get_bbox_to_anchor(),
                                                renderer)
                        for x in range(1, len(self.codes))]

#       tx, ty = self.legendPatch.get_x(), self.legendPatch.get_y()

        candidates = []
        for l, b in consider:
            legendBox = Bbox.from_bounds(l, b, width, height)
            badness = 0
            # XXX TODO: If markers are present, it would be good to
            # take their into account when checking vertex overlaps in
            # the next line.
            badness = legendBox.count_contains(verts)
            badness += legendBox.count_contains(offsets)
            badness += legendBox.count_overlaps(bboxes)
            for line in lines:
                # FIXME: the following line is ill-suited for lines
                # that 'spiral' around the center, because the bbox
                # may intersect with the legend even if the line
                # itself doesn't. One solution would be to break up
                # the line into its straight-segment components, but
                # this may (or may not) result in a significant
                # slowdown if lines with many vertices are present.
                if line.intersects_bbox(legendBox):
                    badness += 1

            ox, oy = l, b
            if badness == 0:
                return ox, oy

            candidates.append((badness, (l, b)))

        # rather than use min() or list.sort(), do this so that we are assured
        # that in the case of two equal badnesses, the one first considered is
        # returned.
        # NOTE: list.sort() is stable.But leave as it is for now. -JJL
        minCandidate = candidates[0]
        for candidate in candidates:
            if candidate[0] < minCandidate[0]:
                minCandidate = candidate

        ox, oy = minCandidate[1]

        return ox, oy
开发者ID:ryanbelt,项目名称:matplotlib,代码行数:62,代码来源:legend.py

示例2: _find_best_position

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
 def _find_best_position(self, width, height, renderer, consider=None):
     """
     Determine the best location to place the legend.
     `consider` is a list of (x, y) pairs to consider as a potential
     lower-left corner of the legend. All are display coords.
     """
     assert self.isaxes # should always hold because function is only called internally
     verts, bboxes, lines = self._auto_legend_data()
     bbox = Bbox.from_bounds(0, 0, width, height)
     consider = [self._get_anchored_bbox(x, bbox, self.get_bbox_to_anchor(),
                                         renderer) for x in range(1, len(self.codes))]
     candidates = []
     for l, b in consider:
         legendBox = Bbox.from_bounds(l, b, width, height)
         badness = 0
         badness = legendBox.count_contains(verts)
         badness += legendBox.count_overlaps(bboxes)
         for line in lines:
             if line.intersects_bbox(legendBox):
                 badness += 1
         ox, oy = l, b
         if badness == 0:
             return ox, oy
         candidates.append((badness, (l, b)))
     minCandidate = candidates[0]
     for candidate in candidates:
         if candidate[0] < minCandidate[0]:
             minCandidate = candidate
     ox, oy = minCandidate[1]
     return ox, oy
开发者ID:,项目名称:,代码行数:32,代码来源:

示例3: adjust_bbox_pdf

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [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)
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:29,代码来源:tight_bbox.py

示例4: connect_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def connect_bbox(bbox1, bbox2, loc1, loc2=None):
        """
        Helper function to obtain a Path from one bbox to another.

        Parameters
        ----------
        bbox1, bbox2 : `matplotlib.transforms.Bbox`
            Bounding boxes to connect.

        loc1 : {1, 2, 3, 4}
            Corner of *bbox1* to use. Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

        loc2 : {1, 2, 3, 4}, optional
            Corner of *bbox2* to use. If None, defaults to *loc1*.
            Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

        Returns
        -------
        path : `matplotlib.path.Path`
            A line segment from the *loc1* corner of *bbox1* to the *loc2*
            corner of *bbox2*.
        """
        if isinstance(bbox1, Rectangle):
            transform = bbox1.get_transform()
            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]]
        codes = [Path.MOVETO, Path.LINETO]

        return Path(verts, codes)
开发者ID:dopplershift,项目名称:matplotlib,代码行数:54,代码来源:inset_locator.py

示例5: _find_best_position

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def _find_best_position(self, width, height, renderer, consider=None):
        """
        Determine the best location to place the legend.

        `consider` is a list of (x, y) pairs to consider as a potential
        lower-left corner of the legend. All are display coords.
        """
        # should always hold because function is only called internally
        assert self.isaxes

        verts, bboxes, lines = self._auto_legend_data()

        bbox = Bbox.from_bounds(0, 0, width, height)
        consider = [self._get_anchored_bbox(x, bbox, self.get_bbox_to_anchor(),
                                            renderer)
                    for x
                    in range(1, len(self.codes))]

        #tx, ty = self.legendPatch.get_x(), self.legendPatch.get_y()

        candidates = []
        for l, b in consider:
            legendBox = Bbox.from_bounds(l, b, width, height)
            badness = 0
            badness = legendBox.count_contains(verts)
            badness += legendBox.count_overlaps(bboxes)
            for line in lines:
                if line.intersects_bbox(legendBox):
                    badness += 1

            ox, oy = l, b
            if badness == 0:
                return ox, oy

            candidates.append((badness, (l, b)))

        # rather than use min() or list.sort(), do this so that we are assured
        # that in the case of two equal badnesses, the one first considered is
        # returned.
        # NOTE: list.sort() is stable.But leave as it is for now. -JJL
        minCandidate = candidates[0]
        for candidate in candidates:
            if candidate[0] < minCandidate[0]:
                minCandidate = candidate

        ox, oy = minCandidate[1]

        return ox, oy
开发者ID:acumartini,项目名称:stock-trading-game,代码行数:50,代码来源:legend.py

示例6: _offset

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
        def _offset(w, h, xd, yd, renderer, fontsize=fontsize, self=self):
            bbox = Bbox.from_bounds(0, 0, w, h)
            borderpad = self.borderpad * fontsize
            bbox_to_anchor = self.get_bbox_to_anchor()

            x0, y0 = self._get_anchored_bbox(self.loc, bbox, bbox_to_anchor, borderpad)
            return x0 + xd, y0 + yd
开发者ID:jjs0sbw,项目名称:CSPLN,代码行数:9,代码来源:offsetbox.py

示例7: set_bbox_to_anchor

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [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)
开发者ID:EnochManohar,项目名称:matplotlib,代码行数:32,代码来源:legend.py

示例8: connect_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [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]]
    codes = [Path.MOVETO, Path.LINETO]
    return Path(verts, codes)
开发者ID:,项目名称:,代码行数:18,代码来源:

示例9: __init__

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def __init__(self, width, height, dpi):
        if __debug__: verbose.report('RendererAgg.__init__', 'debug-annoying')
        RendererBase.__init__(self)
        self.texd = maxdict(50)  # a cache of tex image rasters
        self._fontd = maxdict(50)

        self.dpi = dpi
        self.width = width
        self.height = height
        if __debug__: verbose.report('RendererAgg.__init__ width=%s, height=%s'%(width, height), 'debug-annoying')
        self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
        if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done',
                                     'debug-annoying')
        #self.draw_path = self._renderer.draw_path  # see below
        self.draw_markers = self._renderer.draw_markers
        self.draw_path_collection = self._renderer.draw_path_collection
        self.draw_quad_mesh = self._renderer.draw_quad_mesh
        self.draw_image = self._renderer.draw_image
        self.copy_from_bbox = self._renderer.copy_from_bbox
        self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized
        self.mathtext_parser = MathTextParser('Agg')

        self.bbox = Bbox.from_bounds(0, 0, self.width, self.height)
        if __debug__: verbose.report('RendererAgg.__init__ done',
                                     'debug-annoying')
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:27,代码来源:backend_agg.py

示例10: draw_plot

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def draw_plot(self):
                if self._doRePlot:
                    self._resizeCreateContent()
                if self.background is None:
                    self.background = self.canvas.copy_from_bbox(self.ax.bbox)
                self.foo += 1
                #self.y = numpy.cos(numpy.arange(0.0,1.0,0.1)+self.foo*0.1)
                # Optimization on the blitting: we compute the box where the changes happen
                changes_box = None

                for i in range(len(self.lines)):
                    data=self.channels[i].getNext()
                    
                    if len(data[1])>0:
                        if self.autolim:
                            print self.autolim[0], data[1], self.autolim[1]
                            self.autolim = [ min(self.autolim[0], min(data[1])), \
                                max(self.autolim[1], max(data[1])) ]
                        else:
                            self.autolim = [ min(data[1]), min(data[1]) ]
                        
                        if changes_box is None:
                            changes_box = Bbox.unit()
                        print '>>>>>>>>'
                        print data[0], data[1]
                        changes_box.update_from_data(numpy.array(data[0]), \
                                numpy.array(data[1]), ignore=changes_box.is_unit())
                        
                        if not self._doRePlot and len(data[0]) > 0 :
                            end = data[0][-1]
                            
                            if end > self.begin+self.span:
                                self.begin += self.span
                                self._doRePlot = True
                                print 'do replot'
                        self.lines[i].set_data(data[0], data[1])
                    else:
                        self.lines[i].set_data([], [])
                
                if not changes_box:
                    return
                #self.canvas.restore_region(self.background)
                for line in self.lines:
                    self.ax.draw_artist(line)
                    #print line.get_transform()
                    tr = line.get_transform()
                    
                changes_box_inframe = changes_box.transformed(tr)
                
                box_padding = 5
                (x,y,l,w) = changes_box_inframe.bounds
                changes_box_inframe = Bbox.from_bounds(x-box_padding, \
                    y-box_padding, l+2*box_padding, w+2*box_padding)
                
                #print 
                t0 = time.time()
                self.canvas.blit(None)
                #self.canvas.blit(changes_box_inframe)
                self.blit_time += time.time() - t0
开发者ID:janfrs,项目名称:kwc-ros-pkg,代码行数:61,代码来源:myplot.py

示例11: get_window_extent

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
 def get_window_extent(self, renderer):
     '''
     get the bounding box in display space.
     '''
     self._update_offset_func(renderer)
     w, h, xd, yd = self.get_extent(renderer)
     ox, oy = self.get_offset(w, h, xd, yd, renderer)
     return Bbox.from_bounds(ox-xd, oy-yd, w, h)
开发者ID:AlexSzatmary,项目名称:matplotlib,代码行数:10,代码来源:offsetbox.py

示例12: adjust_bbox_pdf

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
def adjust_bbox_pdf(fig, bbox_inches):
    """
    adjust_bbox for pdf & eps format
    """
    tr = Affine2D().scale(72)
    _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
    f = 72. / fig.dpi
    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)
开发者ID:,项目名称:,代码行数:20,代码来源:

示例13: _calculate_bbox

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [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

示例14: _find_best_position

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
    def _find_best_position(self, width, height, renderer, consider=None):
        """
        Determine the best location to place the legend.

        *consider* is a list of ``(x, y)`` pairs to consider as a potential
        lower-left corner of the legend. All are display coords.
        """
        # should always hold because function is only called internally
        assert self.isaxes

        verts, bboxes, lines, offsets = self._auto_legend_data()
        if self._loc_used_default and verts.shape[0] > 200000:
            # this size results in a 3+ second render time on a good machine
            cbook._warn_external(
                'Creating legend with loc="best" can be slow with large '
                'amounts of data.'
            )

        bbox = Bbox.from_bounds(0, 0, width, height)
        if consider is None:
            consider = [self._get_anchored_bbox(x, bbox,
                                                self.get_bbox_to_anchor(),
                                                renderer)
                        for x in range(1, len(self.codes))]

        candidates = []
        for idx, (l, b) in enumerate(consider):
            legendBox = Bbox.from_bounds(l, b, width, height)
            badness = 0
            # XXX TODO: If markers are present, it would be good to
            # take them into account when checking vertex overlaps in
            # the next line.
            badness = (legendBox.count_contains(verts)
                       + legendBox.count_contains(offsets)
                       + legendBox.count_overlaps(bboxes)
                       + sum(line.intersects_bbox(legendBox, filled=False)
                             for line in lines))
            if badness == 0:
                return l, b
            # Include the index to favor lower codes in case of a tie.
            candidates.append((badness, idx, (l, b)))

        _, _, (l, b) = min(candidates)
        return l, b
开发者ID:jklymak,项目名称:matplotlib,代码行数:46,代码来源:legend.py

示例15: _findoffset_loc

# 需要导入模块: from matplotlib.transforms import Bbox [as 别名]
# 或者: from matplotlib.transforms.Bbox import from_bounds [as 别名]
 def _findoffset_loc(self, width, height, xdescent, ydescent, renderer):
     "Heper function to locate the legend using the location code"
     if iterable(self._loc) and len(self._loc)==2:
         fx, fy = self._loc
         bbox = self.get_bbox_to_anchor()
         x, y = bbox.x0 + bbox.width * fx, bbox.y0 + bbox.height * fy
     else:
         bbox = Bbox.from_bounds(0, 0, width, height)
         x, y = self._get_anchored_bbox(self._loc, bbox, self.get_bbox_to_anchor(), renderer)
     return x+xdescent, y+ydescent
开发者ID:,项目名称:,代码行数:12,代码来源:


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