Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c13491

Browse files
committed
Convert units when returning Rect bbox
1 parent 521754f commit 9c13491

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/matplotlib/patches.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,7 @@ def _update_patch_transform(self):
713713
maxes it very important to call the accessor method and
714714
not directly access the transformation member variable.
715715
"""
716-
x0 = self.convert_xunits(self._x0)
717-
y0 = self.convert_yunits(self._y0)
718-
x1 = self.convert_xunits(self._x1)
719-
y1 = self.convert_yunits(self._y1)
716+
x0, y0, x1, y1 = self._convert_units()
720717
bbox = transforms.Bbox.from_extents(x0, y0, x1, y1)
721718
rot_trans = transforms.Affine2D()
722719
rot_trans.rotate_deg_around(x0, y0, self.angle)
@@ -729,6 +726,16 @@ def _update_x1(self):
729726
def _update_y1(self):
730727
self._y1 = self._y0 + self._height
731728

729+
def _convert_units(self):
730+
'''
731+
Convert bounds of the rectangle
732+
'''
733+
x0 = self.convert_xunits(self._x0)
734+
y0 = self.convert_yunits(self._y0)
735+
x1 = self.convert_xunits(self._x1)
736+
y1 = self.convert_yunits(self._y1)
737+
return x0, y0, x1, y1
738+
732739
def get_patch_transform(self):
733740
self._update_patch_transform()
734741
return self._rect_transform
@@ -746,7 +753,7 @@ def get_xy(self):
746753
return self._x0, self._y0
747754

748755
def get_width(self):
749-
"Return the width of the rectangle"
756+
"Return the width of the rectangle"
750757
return self._width
751758

752759
def get_height(self):
@@ -823,6 +830,7 @@ def set_bounds(self, *args):
823830
self.stale = True
824831

825832
def get_bbox(self):
833+
x0, y0, x1, y1 = self._convert_units()
826834
return transforms.Bbox.from_extents(self._x0, self._y0,
827835
self._x1, self._y1)
828836

0 commit comments

Comments
 (0)