@@ -712,38 +712,62 @@ def set_xy(self, vertices):
712712 :meth:`~matplotlib.patches.Polygon.set_xy` instead.""" )
713713
714714class Wedge (Patch ):
715+ """
716+ Wedge shaped patch.
717+ """
715718 def __str__ (self ):
716719 return "Wedge(%g,%g)" % (self .theta1 ,self .theta2 )
717720
718- def __init__ (self , center , r , theta1 , theta2 , ** kwargs ):
721+ def __init__ (self , center , r , theta1 , theta2 , width = 0 , ** kwargs ):
719722 """
720723 Draw a wedge centered at *x*, *y* center with radius *r* that
721- sweeps *theta1* to *theta2* (in degrees).
724+ sweeps *theta1* to *theta2* (in degrees). If *width* is given,
725+ then a partial wedge is drawn from inner radius *r* - *width*
726+ to outer radius *r*.
722727
723728 Valid kwargs are:
724729
725730 %(Patch)s
726731 """
727732 Patch .__init__ (self , ** kwargs )
728733 self .center = center
729- self .r = r
730- self .theta1 = theta1
731- self .theta2 = theta2
734+ self .r ,self .width = r ,width
735+ self .theta1 ,self .theta2 = theta1 ,theta2
736+
737+ # Inner and outer rings are connected unless the annulus is complete
738+ delta = theta2 - theta1
739+ if abs ((theta2 - theta1 ) - 360 ) <= 1e-12 :
740+ theta1 ,theta2 = 0 ,360
741+ connector = Path .MOVETO
742+ else :
743+ connector = Path .LINETO
744+
745+ # Form the outer ring
746+ arc = Path .arc (theta1 ,theta2 )
747+
748+ if width != 0 :
749+ # Partial annulus needs to draw the outter ring
750+ # followed by a reversed and scaled inner ring
751+ v1 = arc .vertices
752+ v2 = arc .vertices [::- 1 ]* float (r - width )/ r
753+ v = np .vstack ([v1 ,v2 ,v1 [0 ,:],(0 ,0 )])
754+ c = np .hstack ([arc .codes ,arc .codes ,connector ,Path .CLOSEPOLY ])
755+ c [len (arc .codes )]= connector
756+ else :
757+ # Wedge doesn't need an inner ring
758+ v = np .vstack ([arc .vertices ,[(0 ,0 ),arc .vertices [0 ,:],(0 ,0 )]])
759+ c = np .hstack ([arc .codes ,[connector ,connector ,Path .CLOSEPOLY ]])
760+
761+ # Shift and scale the wedge to the final location.
762+ v *= r
763+ v += np .asarray (center )
764+ self ._path = Path (v ,c )
732765 self ._patch_transform = transforms .IdentityTransform ()
733- self ._path = Path .wedge (self .theta1 , self .theta2 )
734766 __init__ .__doc__ = cbook .dedent (__init__ .__doc__ ) % artist .kwdocd
735767
736768 def get_path (self ):
737769 return self ._path
738770
739- def get_patch_transform (self ):
740- x = self .convert_xunits (self .center [0 ])
741- y = self .convert_yunits (self .center [1 ])
742- rx = self .convert_xunits (self .r )
743- ry = self .convert_yunits (self .r )
744- self ._patch_transform = transforms .Affine2D () \
745- .scale (rx , ry ).translate (x , y )
746- return self ._patch_transform
747771
748772# COVERAGE NOTE: Not used internally or from examples
749773class Arrow (Patch ):
@@ -3042,4 +3066,3 @@ def draw(self, renderer):
30423066 self .fill = fill_orig
30433067
30443068 #renderer.close_group('patch')
3045-
0 commit comments