8000 counterclock parameter for pie · matplotlib/matplotlib@a6bbc3c · GitHub
[go: up one dir, main page]

Skip to content

Commit a6bbc3c

Browse files
committed
counterclock parameter for pie
1 parent 97b5251 commit a6bbc3c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ def stem(self, *args, **kwargs):
23402340

23412341
def pie(self, x, explode=None, labels=None, colors=None,
23422342
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):
23442344
r"""
23452345
Plot a pie chart.
23462346
@@ -2394,6 +2394,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
23942394
*radius*: [ *None* | scalar ]
23952395
The radius of the pie, if *radius* is *None* it will be set to 1.
23962396
2397+
*counterclock*: [ *False* | *True* ]
2398+
Specify fractions direction, clockwise or counterclockwise.
2399+
23972400
The pie chart will probably look best if the figure and axes are
23982401
square, or the Axes aspect is equal. e.g.::
23992402
@@ -2453,12 +2456,12 @@ def pie(self, x, explode=None, labels=None, colors=None,
24532456
i = 0
24542457
for frac, label, expl in cbook.safezip(x, labels, explode):
24552458
x, y = center
2456-
theta2 = theta1 + frac
2459+
theta2 = (theta1 + frac) if counterclock else (theta1 - frac)
24572460
thetam = 2 * math.pi * 0.5 * (theta1 + theta2)
24582461
x += expl * math.cos(thetam)
24592462
y += expl * math.sin(thetam)
24602463

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),
24622465
facecolor=colors[i % len(colors)])
24632466
slices.append(w)
24642467
self.add_patch(w)

0 commit comments

Comments
 (0)
0