Skip to content

Commit fea21af

Browse files
authored
Merge pull request #21400 from anntzer/bboxprops
Use bbox.{size,bounds,width,height,p0,...} where appropriate.
2 parents cced93b + 8349be6 commit fea21af

File tree

10 files changed

+22
-32
lines changed

10 files changed

+22
-32
lines changed

examples/shapes_and_collections/fancybox_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545

4646
def add_fancy_patch_around(ax, bb, **kwargs):
47-
fancy = FancyBboxPatch((bb.xmin, bb.ymin), bb.width, bb.height,
47+
fancy = FancyBboxPatch(bb.p0, bb.width, bb.height,
4848
fc=(1, 0.8, 1, 0.5), ec=(1, 0.5, 1, 0.5),
4949
**kwargs)
5050
ax.add_patch(fancy)

lib/matplotlib/backends/backend_wxcairo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ def __init__(self, parent, id, figure):
3030
self._renderer = RendererCairo(self.figure.dpi)
3131

3232
def draw(self, drawDC=None):
33-
width = int(self.figure.bbox.width)
34-
height = int(self.figure.bbox.height)
35-
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
33+
size = self.figure.bbox.size.astype(int)
34+
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, *size)
3635
self._renderer.set_ctx_from_surface(surface)
37-
self._renderer.set_width_height(width, height)
36+
self._renderer.set_width_height(*size)
3837
self._renderer.dpi = self.figure.dpi
3938
self.figure.draw(self._renderer)
4039
self.bitmap = wxcairo.BitmapFromImageSurface(surface)

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
16271627

16281628
for a in artists:
16291629
bbox = a.get_tightbbox(renderer)
1630-
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
1630+
if bbox is not None:
16311631
bb.append(bbox)
16321632

16331633
for ax in self.axes:

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def draw(self, renderer):
621621
# update the location and size of the legend. This needs to
622622
# be done in any case to clip the figure right.
623623
bbox = self._legend_box.get_window_extent(renderer)
624-
self.legendPatch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height)
624+
self.legendPatch.set_bounds(bbox.bounds)
625625
self.legendPatch.set_mutation_scale(fontsize)
626626

627627
if self.shadow:

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def draw(self, renderer):
557557
self.stale = False
558558

559559
def update_frame(self, bbox, fontsize=None):
560-
self.patch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height)
560+
self.patch.set_bounds(bbox.bounds)
561561
if fontsize:
562562
self.patch.set_mutation_scale(fontsize)
563563
self.stale = True
@@ -811,7 +811,7 @@ def get_extent(self, renderer):
811811
ismath="TeX" if self._text.get_usetex() else False)
812812

813813
bbox, info, yd = self._text._get_layout(renderer)
814-
w, h = bbox.width, bbox.height
814+
w, h = bbox.size
815815

816816
self._baseline_transform.clear()
817817

@@ -1111,7 +1111,7 @@ def _offset(w, h, xd, yd, renderer):
11111111
self.set_offset(_offset)
11121112

11131113
def update_frame(self, bbox, fontsize=None):
1114-
self.patch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height)
1114+
self.patch.set_bounds(bbox.bounds)
11151115
if fontsize:
11161116
self.patch.set_mutation_scale(fontsize)
11171117

@@ -1146,8 +1146,7 @@ def _get_anchored_bbox(loc, bbox, parentbbox, borderpad):
11461146
# validated. If 0 (None), we just let ``bbox.anchored`` raise.
11471147
c = [None, "NE", "NW", "SW", "SE", "E", "W", "E", "S", "N", "C"][loc]
11481148
container = parentbbox.padded(-borderpad)
1149-
anchored_box = bbox.anchored(c, container=container)
1150-
return anchored_box.x0, anchored_box.y0
1149+
return bbox.anchored(c, container=container).p0
11511150

11521151

11531152
class AnchoredText(AnchoredOffsetbox):
@@ -1487,8 +1486,7 @@ def _update_position_xybox(self, renderer, xy_pixel):
14871486

14881487
# update patch position
14891488
bbox = self.offsetbox.get_window_extent(renderer)
1490-
self.patch.set_bounds(bbox.x0, bbox.y0,
1491-
bbox.width, bbox.height)
1489+
self.patch.set_bounds(bbox.bounds)
14921490

14931491
x, y = xy_pixel
14941492

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
21062106
box returned by an artist's `.Artist.get_window_extent`
21072107
to test whether the artist is returning the correct bbox.
21082108
"""
2109-
r = Rectangle(xy=(bbox.x0, bbox.y0), width=bbox.width, height=bbox.height,
2109+
r = Rectangle(xy=bbox.p0, width=bbox.width, height=bbox.height,
21102110
edgecolor=color, fill=False, clip_on=False)
21112111
if trans is not None:
21122112
r.set_transform(trans)

lib/matplotlib/quiver.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,9 @@ def _dots_per_unit(self, units):
605605
elif units == 'y':
606606
dx0 = self.axes.viewLim.height
607607
dx1 = self.axes.bbox.height
608-
else: # 'xy' is assumed
609-
dxx0 = self.axes.viewLim.width
610-
dxx1 = self.axes.bbox.width
611-
dyy0 = self.axes.viewLim.height
612-
dyy1 = self.axes.bbox.height
613-
dx1 = np.hypot(dxx1, dyy1)
614-
dx0 = np.hypot(dxx0, dyy0)
608+
else: # 'xy', i.e. hypot(x, y)
609+
dx0 = np.hypot(*self.axes.viewLim.size)
610+
dx1 = np.hypot(*self.axes.bbox.size)
615611
dx = dx1 / dx0
616612
else:
617613
if units == 'width':

lib/matplotlib/tight_bbox.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ def restore_bbox():
5757
tr = Affine2D().scale(fixed_dpi)
5858
dpi_scale = fixed_dpi / fig.dpi
5959

60-
fig.bbox_inches = Bbox.from_bounds(0, 0,
61-
bbox_inches.width, bbox_inches.height)
60+
fig.bbox_inches = Bbox.from_bounds(0, 0, *bbox_inches.size)
6261
x0, y0 = tr.transform(bbox_inches.p0)
63-
w1, h1 = fig.bbox.width * dpi_scale, fig.bbox.height * dpi_scale
62+
w1, h1 = fig.bbox.size * dpi_scale
6463
fig.transFigure._boxout = Bbox.from_bounds(-x0, -y0, w1, h1)
6564
fig.transFigure.invalidate()
6665

lib/matplotlib/widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,12 @@ def _rendercursor(self):
12071207
bb_widthtext = self.text_disp.get_window_extent()
12081208

12091209
if bb_text.y0 == bb_text.y1: # Restoring the height if no text.
1210-
bb_text.y0 -= (bb_widthtext.y1-bb_widthtext.y0)/2
1211-
bb_text.y1 += (bb_widthtext.y1-bb_widthtext.y0)/2
1210+
bb_text.y0 -= bb_widthtext.height / 2
1211+
bb_text.y1 += bb_widthtext.height / 2
12121212
elif not widthtext: # Keep width to 0.
12131213
bb_text.x1 = bb_text.x0
12141214
else: # Move the cursor using width of bb_widthtext.
1215-
bb_text.x1 = bb_text.x0 + (bb_widthtext.x1 - bb_widthtext.x0)
1215+
bb_text.x1 = bb_text.x0 + bb_widthtext.width
12161216

12171217
self.cursor.set(
12181218
segments=[[(bb_text.x1, bb_text.y0), (bb_text.x1, bb_text.y1)]],

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
205205
hh = (oy[-1] - oy[0]) / fig_h
206206
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
207207
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
208-
pb1_anchored = pb1.anchored(self.get_anchor(), pb)
209-
x0, y0 = pb1_anchored.x0, pb1_anchored.y0
208+
x0, y0 = pb1.anchored(self.get_anchor(), pb).p0
210209

211210
else:
212211
ox = self._calc_offsets(hsizes, k_h)
@@ -637,8 +636,7 @@ def _locate(x, y, w, h, summed_widths, equal_heights, fig_w, fig_h, anchor):
637636
hh = (karray[0]*h0_r + h0_a) / fig_h
638637
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
639638
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
640-
pb1_anchored = pb1.anchored(anchor, pb)
641-
x0, y0 = pb1_anchored.x0, pb1_anchored.y0
639+
x0, y0 = pb1.anchored(anchor, pb).p0
642640

643641
return x0, y0, ox, hh
644642

0 commit comments

Comments
 (0)