10000 Use rectangle coords instead of width/height · matplotlib/matplotlib@bb755f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb755f6

Browse files
committed
Use rectangle coords instead of width/height
1 parent 225a4a0 commit bb755f6

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

lib/matplotlib/patches.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,15 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
688688

689689
Patch.__init__(self, **kwargs)
690690

691-
self._x = xy[0]
692-
self._y = xy[1]
691+
self._x0 = xy[0]
692+
self._y0 = xy[1]
693+
693694
self._width = width
694695
self._height = height
696+
697+
self._x1 = self._x0 + self._width
698+
self._y1 = self._y0 + self._height
699+
695700
self.angle = float(angle)
696701
# Note: This cannot be calculated until this is added to an Axes
697702
self._rect_transform = transforms.IdentityTransform()
@@ -708,13 +713,13 @@ def _update_patch_transform(self):
708713
maxes it very important to call the accessor method and
709714
not directly access the transformation member variable.
710715
"""
711-
x = self.convert_xunits(self._x)
712-
y = self.convert_yunits(self._y)
713-
width = self.convert_xunits(self._width)
714-
height = self.convert_yunits(self._height)
715-
bbox = transforms.Bbox.from_bounds(x, y, width, height)
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)
720+
bbox = transforms.Bbox.from_extents(x0, y0, x1, y1)
716721
rot_trans = transforms.Affine2D()
717-
rot_trans.rotate_deg_around(x, y, self.angle)
722+
rot_trans.rotate_deg_around(x0, y0, self.angle)
718723
self._rect_transform = transforms.BboxTransformTo(bbox)
719724
self._rect_transform += rot_trans
720725

@@ -724,15 +729,15 @@ def get_patch_transform(self):
724729

725730
def get_x(self):
726731
"Return the left coord of the rectangle"
727-
return self._x
732+
return self._x0
728733

729734
def get_y(self):
730735
"Return the bottom coord of the rectangle"
731-
return self._y
736+
return self._y0
732737

733738
def get_xy(self):
734739
"Return the left and bottom coords of the rectangle"
735-
return self._x, self._y
740+
return self._x0, self._y0
736741

737742
def get_width(self):
738743
"Return the width of the rectangle"
@@ -748,7 +753,7 @@ def set_x(self, x):
748753
749754
ACCEPTS: float
750755
"""
751-
self._x = x
756+
self._x0 = x0
752757
self.stale = True
753758

754759
def set_y(self, y):
@@ -757,7 +762,7 @@ def set_y(self, y):
757762
758763
ACCEPTS: float
759764
"""
760-
self._y = y
765+
self._y0 = y0
761766
self.stale = True
762767

763768
def set_xy(self, xy):
@@ -766,7 +771,7 @@ def set_xy(self, xy):
766771
767772
ACCEPTS: 2-item sequence
768773
"""
769-
self._x, self._y = xy
774+
self._x0, self._y0 = xy
770775
self.stale = True
771776

772777
def set_width(self, w):
@@ -776,6 +781,7 @@ def set_width(self, w):
776781
ACCEPTS: float
777782
"""
778783
self._width = w
784+
self._x1 = self._x0 + w
779785
self.stale = True
780786

781787
def set_height(self, h):
@@ -785,6 +791,7 @@ def set_height(self, h):
785791
ACCEPTS: float
786792
"""
787793
self._height = h
794+
self._y1 = self._y0 + h
788795
self.stale = True
789796

790797
def set_bounds(self, *args):
@@ -797,15 +804,17 @@ def set_bounds(self, *args):
797804
l, b, w, h = args[0]
798805
else:
799806
l, b, w, h = args
800-
self._x = l
801-
self._y = b
807+
self._x0 = l
808+
self._y0 = b
802809
self._width = w
803810
self._height = h
811+
self._x0 = l + w
812+
self._y0 = b + h
804813
self.stale = True
805814

806815
def get_bbox(self):
807-
return transforms.Bbox.from_bounds(self._x, self._y,
808-
self._width, self._height)
816+
return transforms.Bbox.from_extents(self._x0, self._y0,
817+
self._x1, self._y1)
809818

810819
xy = property(get_xy, set_xy)
811820

0 commit comments

Comments
 (0)
0