File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -799,6 +799,10 @@ def get_height(self):
799799 """Return the height of the rectangle."""
800800 return self ._height
801801
802+ def get_angle (self ):
803+ """Get the rotation angle in degrees."""
804+ return self .angle
805+
802806 def set_x (self , x ):
803807 """Set the left coordinate of the rectangle."""
804808 self ._x0 = x
@@ -809,6 +813,15 @@ def set_y(self, y):
809813 self ._y0 = y
810814 self .stale = True
811815
816+ def set_angle (self , angle ):
817+ """
818+ Set the rotation angle in degrees.
819+
820+ The rotation is performed anti-clockwise around *xy*.
821+ """
822+ self .angle = angle
823+ self .stale = True
824+
812825 def set_xy (self , xy ):
813826 """
814827 Set the left and bottom coordinates of the rectangle.
Original file line number Diff line number Diff line change @@ -76,6 +76,27 @@ def test_rotate_rect():
7676 assert_almost_equal (rect1 .get_verts (), new_verts )
7777
7878
79+ @check_figures_equal (extensions = ['png' ])
80+ def test_rotate_rect_draw (fig_test , fig_ref ):
81+ ax_test = fig_test .add_subplot ()
82+ ax_ref = fig_ref .add_subplot ()
83+
84+ loc = (0 , 0 )
85+ width , height = (1 , 1 )
86+ angle = 30
87+ rect_ref = Rectangle (loc , width , height , angle = angle )
88+ ax_ref .add_patch (rect_ref )
89+ assert rect_ref .get_angle () == angle
90+
91+ # Check that when the angle is updated after adding to an axes, that the
92+ # patch is marked stale and redrawn in the correct location
93+ rect_test = Rectangle (loc , width , height )
94+ assert rect_test .get_angle () == 0
95+ ax_test .add_patch (rect_test )
96+ rect_test .set_angle (angle )
97+ assert rect_test .get_angle () == angle
98+
99+
79100def test_negative_rect ():
80101 # These two rectangles have the same vertices, but starting from a
81102 # different point. (We also drop the last vertex, which is a duplicate.)
You can’t perform that action at this time.
0 commit comments