@@ -669,7 +669,7 @@ class Rectangle(Patch):
669
669
"""
670
670
671
671
def __str__ (self ):
672
- pars = self ._x , self ._y , self ._width , self ._height , self .angle
672
+ pars = self ._x0 , self ._y0 , self ._width , self ._height , self .angle
673
673
fmt = "Rectangle(xy=(%g, %g), width=%g, height=%g, angle=%g)"
674
674
return fmt % pars
675
675
@@ -688,10 +688,15 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
688
688
689
689
Patch .__init__ (self , ** kwargs )
690
690
691
- self ._x = xy [0 ]
692
- self ._y = xy [1 ]
691
+ self ._x0 = xy [0 ]
692
+ self ._y0 = xy [1 ]
693
+
693
694
self ._width = width
694
695
self ._height = height
696
+
697
+ self ._x1 = self ._x0 + self ._width
698
+ self ._y1 = self ._y0 + self ._height
699
+
695
700
self .angle = float (angle )
696
701
# Note: This cannot be calculated until this is added to an Axes
697
702
self ._rect_transform = transforms .IdentityTransform ()
@@ -708,31 +713,37 @@ def _update_patch_transform(self):
708
713
maxes it very important to call the accessor method and
709
714
not directly access the transformation member variable.
710
715
"""
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 )
716
721
rot_trans = transforms .Affine2D ()
717
- rot_trans .rotate_deg_around (x , y , self .angle )
722
+ rot_trans .rotate_deg_around (x0 , y0 , self .angle )
718
723
self ._rect_transform = transforms .BboxTransformTo (bbox )
719
724
self ._rect_transform += rot_trans
720
725
726
+ def _update_x1 (self ):
727
+ self ._x1 = self ._x0 + self ._width
728
+
729
+ def _update_y1 (self ):
730
+ self ._y1 = self ._y0 + self ._height
731
+
721
732
def get_patch_transform (self ):
722
733
self ._update_patch_transform ()
723
734
return self ._rect_transform
724
735
725
736
def get_x (self ):
726
737
"Return the left coord of the rectangle"
727
- return self ._x
738
+ return self ._x0
728
739
729
740
def get_y (self ):
730
741
"Return the bottom coord of the rectangle"
731
- return self ._y
742
+ return self ._y0
732
743
733
744
def get_xy (self ):
734
745
"Return the left and bottom coords of the rectangle"
735
- return self ._x , self ._y
746
+ return self ._x0 , self ._y0
736
747
737
748
def get_width (self ):
738
749
"Return the width of the rectangle"
@@ -748,7 +759,8 @@ def set_x(self, x):
748
759
749
760
ACCEPTS: float
750
761
"""
751
- self ._x = x
762
+ self ._x0 = x
763
+ self ._update_x1 ()
752
764
self .stale = True
753
765
754
766
def set_y (self , y ):
@@ -757,7 +769,8 @@ def set_y(self, y):
757
769
758
770
ACCEPTS: float
759
771
"""
760
- self ._y = y
772
+ self ._y0 = y
773
+ self ._update_y1 ()
761
774
self .stale = True
762
775
763
776
def set_xy (self , xy ):
@@ -766,7 +779,9 @@ def set_xy(self, xy):
766
779
767
780
ACCEPTS: 2-item sequence
768
781
"""
769
- self ._x , self ._y = xy
782
+ self ._x0 , self ._y0 = xy
783
+ self ._update_x1 ()
784
+ self ._update_y1 ()
770
785
self .stale = True
771
786
772
787
def set_width (self , w ):
@@ -776,6 +791,7 @@ def set_width(self, w):
776
791
ACCEPTS: float
777
792
"""
778
793
self ._width = w
794
+ self ._update_x1 ()
779
795
self .stale = True
780
796
781
797
def set_height (self , h ):
@@ -785,6 +801,7 @@ def set_height(self, h):
785
801
ACCEPTS: float
786
802
"""
787
803
self ._height = h
804
+ self ._update_y1 ()
788
805
self .stale = True
789
806
790
807
def set_bounds (self , * args ):
@@ -797,15 +814,17 @@ def set_bounds(self, *args):
797
814
l , b , w , h = args [0 ]
798
815
else :
799
816
l , b , w , h = args
800
- self ._x = l
801
- self ._y = b
817
+ self ._x0 = l
818
+ self ._y0 = b
802
819
self ._width = w
803
820
self ._height = h
821
+ self ._update_x1 ()
822
+ self ._update_y1 ()
804
823
self .stale = True
805
824
806
825
def get_bbox (self ):
807
- return transforms .Bbox .from_bounds (self ._x , self ._y ,
808
- self ._width , self ._height )
826
+ return transforms .Bbox .from_extents (self ._x0 , self ._y0 ,
827
+ self ._x1 , self ._y1 )
809
828
810
829
xy = property (get_xy , set_xy )
811
830
0 commit comments