Python matplotlib.transforms.Bbox.from_bounds() Examples
The following are 30
code examples of matplotlib.transforms.Bbox.from_bounds().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.transforms.Bbox
, or try the search function
.
Example #1
Source File: colorbar.py From Computable with MIT License | 6 votes |
def __call__(self, axes, renderer): """ Return the adjusted position of the axes """ bbox0 = self.get_original_position(axes, renderer) bbox = bbox0 x1, y1, w, h = bbox.bounds extesion_fraction = self.extesion_fraction dw, dh = w*extesion_fraction, h*extesion_fraction if self.extend in ["min", "both"]: if self.orientation == "horizontal": x1 = x1 + dw else: y1 = y1+dh if self.extend in ["max", "both"]: if self.orientation == "horizontal": w = w-2*dw else: h = h-2*dh return Bbox.from_bounds(x1, y1, w, h)
Example #2
Source File: offsetbox.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform self.stale = True
Example #3
Source File: inset_locator.py From matplotlib-4-abaqus with MIT License | 6 votes |
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)
Example #4
Source File: offsetbox.py From Computable with MIT License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform
Example #5
Source File: offsetbox.py From Computable with MIT License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #6
Source File: offsetbox.py From neural-network-animation with MIT License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform
Example #7
Source File: offsetbox.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #8
Source File: colorbar.py From matplotlib-4-abaqus with MIT License | 6 votes |
def __call__(self, axes, renderer): """ Return the adjusted position of the axes """ bbox0 = self.get_original_position(axes, renderer) bbox = bbox0 x1, y1, w, h = bbox.bounds extesion_fraction = self.extesion_fraction dw, dh = w*extesion_fraction, h*extesion_fraction if self.extend in ["min", "both"]: if self.orientation == "horizontal": x1 = x1 + dw else: y1 = y1+dh if self.extend in ["max", "both"]: if self.orientation == "horizontal": w = w-2*dw else: h = h-2*dh return Bbox.from_bounds(x1, y1, w, h)
Example #9
Source File: colorbar.py From matplotlib-4-abaqus with MIT License | 6 votes |
def __call__(self, axes, renderer): """ Return the adjusted position of the axes """ bbox0 = self.get_original_position(axes, renderer) bbox = bbox0 x1, y1, w, h = bbox.bounds extesion_fraction = self.extesion_fraction dw, dh = w*extesion_fraction, h*extesion_fraction if self.extend in ["min", "both"]: if self.orientation == "horizontal": x1 = x1 + dw else: y1 = y1+dh if self.extend in ["max", "both"]: if self.orientation == "horizontal": w = w-2*dw else: h = h-2*dh return Bbox.from_bounds(x1, y1, w, h)
Example #10
Source File: backend_agg.py From matplotlib-4-abaqus with MIT License | 6 votes |
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.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) self._filter_renderers = [] if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done', 'debug-annoying') self._update_methods() 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')
Example #11
Source File: tight_bbox.py From Computable with MIT License | 6 votes |
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)
Example #12
Source File: colorbar.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def __call__(self, axes, renderer): """ Return the adjusted position of the axes """ bbox0 = self.get_original_position(axes, renderer) bbox = bbox0 x1, y1, w, h = bbox.bounds extesion_fraction = self.extesion_fraction dw, dh = w*extesion_fraction, h*extesion_fraction if self.extend in ["min", "both"]: if self.orientation == "horizontal": x1 = x1 + dw else: y1 = y1+dh if self.extend in ["max", "both"]: if self.orientation == "horizontal": w = w-2*dw else: h = h-2*dh return Bbox.from_bounds(x1, y1, w, h)
Example #13
Source File: backend_agg.py From Computable with MIT License | 6 votes |
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.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) self._filter_renderers = [] if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done', 'debug-annoying') self._update_methods() 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')
Example #14
Source File: colorbar.py From Computable with MIT License | 6 votes |
def __call__(self, axes, renderer): """ Return the adjusted position of the axes """ bbox0 = self.get_original_position(axes, renderer) bbox = bbox0 x1, y1, w, h = bbox.bounds extesion_fraction = self.extesion_fraction dw, dh = w*extesion_fraction, h*extesion_fraction if self.extend in ["min", "both"]: if self.orientation == "horizontal": x1 = x1 + dw else: y1 = y1+dh if self.extend in ["max", "both"]: if self.orientation == "horizontal": w = w-2*dw else: h = h-2*dh return Bbox.from_bounds(x1, y1, w, h)
Example #15
Source File: plot.py From mplhep with MIT License | 6 votes |
def ylow(ax=None, ylow=None): """ Set lower y limit to 0 if not data/errors go lower. Or set a specific value """ if ax is None: ax = plt.gca() if ylow is None: # Check full figsize below 0 bbox = Bbox.from_bounds( 0, 0, ax.get_window_extent().width, -ax.get_window_extent().height ) if overlap(ax, bbox) == 0: ax.set_ylim(0, None) else: ydata = overlap(ax, bbox, get_vertices=True)[1][:, 1] ax.set_ylim(np.min([np.min(ydata), ax.get_ylim()[0]]), None) else: ax.set_ylim(0, ax.get_ylim()[-1]) return ax
Example #16
Source File: inset_locator.py From Computable with MIT License | 6 votes |
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)
Example #17
Source File: tight_bbox.py From matplotlib-4-abaqus with MIT License | 6 votes |
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)
Example #18
Source File: offsetbox.py From neural-network-animation with MIT License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #19
Source File: legend.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _findoffset(self, width, height, xdescent, ydescent, renderer): "Helper function to locate the legend." if self._loc == 0: # "best". x, y = self._find_best_position(width, height, renderer) elif self._loc in Legend.codes.values(): # Fixed location. bbox = Bbox.from_bounds(0, 0, width, height) x, y = self._get_anchored_bbox(self._loc, bbox, self.get_bbox_to_anchor(), renderer) else: # Axes or figure coordinates. fx, fy = self._loc bbox = self.get_bbox_to_anchor() x, y = bbox.x0 + bbox.width * fx, bbox.y0 + bbox.height * fy return x + xdescent, y + ydescent
Example #20
Source File: offsetbox.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform self.stale = True
Example #21
Source File: offsetbox.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #22
Source File: offsetbox.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #23
Source File: legend.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _findoffset(self, width, height, xdescent, ydescent, renderer): "Helper function to locate the legend." if self._loc == 0: # "best". x, y = self._find_best_position(width, height, renderer) elif self._loc in Legend.codes.values(): # Fixed location. bbox = Bbox.from_bounds(0, 0, width, height) x, y = self._get_anchored_bbox(self._loc, bbox, self.get_bbox_to_anchor(), renderer) else: # Axes or figure coordinates. fx, fy = self._loc bbox = self.get_bbox_to_anchor() x, y = bbox.x0 + bbox.width * fx, bbox.y0 + bbox.height * fy return x + xdescent, y + ydescent
Example #24
Source File: offsetbox.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform self.stale = True
Example #25
Source File: offsetbox.py From matplotlib-4-abaqus with MIT License | 6 votes |
def _update_offset_func(self, renderer, fontsize=None): """ Update the offset func which depends on the dpi of the renderer (because of the padding). """ if fontsize is None: fontsize = renderer.points_to_pixels( self.prop.get_size_in_points()) 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 self.set_offset(_offset)
Example #26
Source File: offsetbox.py From matplotlib-4-abaqus with MIT License | 6 votes |
def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be transformed to display coordinate by the given transform. """ if bbox is None or 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) self._bbox_to_anchor_transform = transform
Example #27
Source File: backend_agg.py From neural-network-animation with MIT License | 6 votes |
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.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) self._filter_renderers = [] if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done', 'debug-annoying') self._update_methods() 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')
Example #28
Source File: offsetbox.py From neural-network-animation with MIT License | 5 votes |
def get_window_extent(self, renderer): ''' get the bounding box in display space. ''' w, h, xd, yd = self.get_extent(renderer) ox, oy = self.get_offset() return mtransforms.Bbox.from_bounds(ox - xd, oy - yd, w, h)
Example #29
Source File: legend.py From neural-network-animation with MIT License | 5 votes |
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)
Example #30
Source File: tight_bbox.py From matplotlib-4-abaqus with MIT License | 5 votes |
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)