@@ -643,29 +643,43 @@ class Rectangle(Patch):
643
643
"""
644
644
645
645
def __str__ (self ):
646
- pars = self ._x , self ._y , self ._width , self ._height , self .angle
646
+ pars = self ._x0 , self ._y0 , self ._width , self ._height , self .angle
647
647
fmt = "Rectangle(xy=(%g, %g), width=%g, height=%g, angle=%g)"
648
648
return fmt % pars
649
649
650
650
@docstring .dedent_interpd
651
651
def __init__ (self , xy , width , height , angle = 0.0 , ** kwargs ):
652
652
"""
653
+ Parameters
654
+ ----------
655
+ xy: length-2 tuple
656
+ The bottom and left rectangle coordinates
657
+ width:
658
+ Rectangle width
659
+ height:
660
+ Rectangle height
661
+ angle: float, optional
662
+ rotation in degrees anti-clockwise about *xy* (default is 0.0)
663
+ fill: bool, optional
664
+ Whether to fill the rectangle (default is ``True``)
653
665
654
- *angle*
655
- rotation in degrees (anti-clockwise)
656
-
657
- *fill* is a boolean indicating whether to fill the rectangle
658
-
666
+ Notes
667
+ -----
659
668
Valid kwargs are:
660
669
%(Patch)s
661
670
"""
662
671
663
672
Patch .__init__ (self , ** kwargs )
664
673
665
- self ._x = xy [0 ]
666
- self ._y = xy [1 ]
674
+ self ._x0 = xy [0 ]
675
+ self ._y0 = xy [1 ]
676
+
667
677
self ._width = width
668
678
self ._height = height
679
+
680
+ self ._x1 = self ._x0 + self ._width
681
+ self ._y1 = self ._y0 + self ._height
682
+
669
683
self .angle = float (angle )
670
684
# Note: This cannot be calculated until this is added to an Axes
671
685
self ._rect_transform = transforms .IdentityTransform ()
@@ -682,56 +696,63 @@ def _update_patch_transform(self):
682
696
makes it very important to call the accessor method and
683
697
not directly access the transformation member variable.
684
698
"""
685
- x = self .convert_xunits (self ._x )
686
- y = self .convert_yunits (self ._y )
687
- width = self .convert_xunits (self ._width )
688
- height = self .convert_yunits (self ._height )
689
- bbox = transforms .Bbox .from_bounds (x , y , width , height )
699
+ x0 , y0 , x1 , y1 = self ._convert_units ()
700
+ bbox = transforms .Bbox .from_extents (x0 , y0 , x1 , y1 )
690
701
rot_trans = transforms .Affine2D ()
691
- rot_trans .rotate_deg_around (x , y , self .angle )
702
+ rot_trans .rotate_deg_around (x0 , y0 , self .angle )
692
703
self ._rect_transform = transforms .BboxTransformTo (bbox )
693
704
self ._rect_transform += rot_trans
694
705
706
+ def _update_x1 (self ):
707
+ self ._x1 = self ._x0 + self ._width
708
+
709
+ def _update_y1 (self ):
710
+ self ._y1 = self ._y0 + self ._height
711
+
712
+ def _convert_units (self ):
713
+ '''
714
+ Convert bounds of the rectangle
715
+ '''
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
+ return x0 , y0 , x1 , y1
721
+
695
722
def get_patch_transform (self ):
696
723
self ._update_patch_transform ()
697
724
return self ._rect_transform
698
725
699
726
def get_x (self ):
700
727
"Return the left coord of the rectangle"
701
- return self ._x
728
+ return self ._x0
702
729
703
730
def get_y (self ):
704
731
"Return the bottom coord of the rectangle"
705
- return self ._y
732
+ return self ._y0
706
733
707
734
def get_xy (self ):
708
735
"Return the left and bottom coords of the rectangle"
709
- return self ._x , self ._y
736
+ return self ._x0 , self ._y0
710
737
711
738
def get_width (self ):
712
- "Return the width of the rectangle"
739
+ "Return the width of the rectangle"
713
740
return self ._width
714
741
715
742
def get_height (self ):
716
743
"Return the height of the rectangle"
717
744
return self ._height
718
745
719
746
def set_x (self , x ):
720
- """
721
- Set the left coord of the rectangle
722
-
723
- ACCEPTS: float
724
- """
725
- self ._x = x
747
+ "Set the left coord of the rectangle"
748
+ self ._x0 = x
749
+ self ._update_x1 ()
726
750
self .stale = True
727
751
728
752
def set_y (self , y ):
729
- """
730
- Set the bottom coord of the rectangle
731
-
732
- ACCEPTS: float
733
- """
734
- self ._y = y
753
+ "Set the bottom coord of the rectangle"
754
+ self ._y0 = y
755
+ self ._update_y1 ()
735
756
self .stale = True
736
757
737
758
def set_xy (self , xy ):
@@ -740,25 +761,21 @@ def set_xy(self, xy):
740
761
741
762
ACCEPTS: 2-item sequence
742
763
"""
743
- self ._x , self ._y = xy
764
+ self ._x0 , self ._y0 = xy
765
+ self ._update_x1 ()
766
+ self ._update_y1 ()
744
767
self .stale = True
745
768
746
769
def set_width (self , w ):
747
- """
748
- Set the width rectangle
749
-
750
- ACCEPTS: float
751
- """
770
+ "Set the width of the rectangle"
752
771
self ._width = w
772
+ self ._update_x1 ()
753
773
self .stale = True
754
774
755
775
def set_height (self , h ):
756
- """
757
- Set the width rectangle
758
-
759
- ACCEPTS: float
760
- """
776
+ "Set the height of the rectangle"
761
777
self ._height = h
778
+ self ._update_y1 ()
762
779
self .stale = True
763
780
764
781
def set_bounds (self , * args ):
@@ -771,15 +788,18 @@ def set_bounds(self, *args):
771
788
l , b , w , h = args [0 ]
772
789
else :
773
790
l , b , w , h = args
774
- self ._x = l
775
- self ._y = b
791
+ self ._x0 = l
792
+ self ._y0 = b
776
793
self ._width = w
777
794
self ._height = h
795
+ self ._update_x1 ()
796
+ self ._update_y1 ()
778
797
self .stale = True
779
798
780
799
def get_bbox (self ):
781
- return transforms .Bbox .from_bounds (self ._x , self ._y ,
782
- self ._width , self ._height )
800
+ x0 , y0 , x1 , y1 = self ._convert_units ()
801
+ return transforms .Bbox .from_extents (self ._x0 , self ._y0 ,
802
+ self ._x1 , self ._y1 )
783
803
784
804
xy = property (get_xy , set_xy )
785
805
0 commit comments