@@ -2340,7 +2340,7 @@ def stem(self, *args, **kwargs):
2340
2340
2341
2341
def pie (self , x , explode = None , labels = None , colors = None ,
2342
2342
autopct = None , pctdistance = 0.6 , shadow = False ,
2343
- labeldistance = 1.1 , startangle = None , radius = None ):
2343
+ labeldistance = 1.1 , startangle = None , radius = None , counterclock = True ):
2344
2344
r"""
2345
2345
Plot a pie chart.
2346
2346
@@ -2394,6 +2394,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
2394
2394
*radius*: [ *None* | scalar ]
2395
2395
The radius of the pie, if *radius* is *None* it will be set to 1.
2396
2396
2397
+ *counterclock*: [ *False* | *True* ]
2398
+ Specify fractions direction, clockwise or counterclockwise.
2399
+
2397
2400
The pie chart will probably look best if the figure and axes are
2398
2401
square, or the Axes aspect is equal. e.g.::
2399
2402
@@ -2453,12 +2456,12 @@ def pie(self, x, explode=None, labels=None, colors=None,
2453
2456
i = 0
2454
2457
for frac , label , expl in cbook .safezip (x , labels , explode ):
2455
2458
x , y = center
2456
- theta2 = theta1 + frac
2459
+ theta2 = ( theta1 + frac ) if counterclock else ( theta1 - frac )
2457
2460
thetam = 2 * math .pi * 0.5 * (theta1 + theta2 )
2458
2461
x += expl * math .cos (thetam )
2459
2462
y += expl * math .sin (thetam )
2460
2463
2461
- w = mpatches .Wedge ((x , y ), radius , 360. * theta1 , 360. * theta2 ,
2464
+ w = mpatches .Wedge ((x , y ), radius , 360. * min ( theta1 , theta2 ), 360. * max ( theta1 , theta2 ) ,
2462
2465
facecolor = colors [i % len (colors )])
2463
2466
slices .append (w )
2464
2467
self .add_patch (w )
0 commit comments