Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counterclock parameter for pie #2853

Merged
merged 4 commits into from
Mar 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2014-03-13 Add parameter 'clockwise' to function pie, True by default.

2014-27-02 Implemented separate horizontal/vertical axes padding to the
ImageGrid in the AxesGrid toolkit

Expand Down
2 changes: 2 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ original location:
tuple-like if separate axis padding is required.
The original behavior is preserved.

* Added clockwise parameter to control sectors direction in `axes.pie`


.. _changes_in_1_3:

Expand Down
14 changes: 9 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2339,8 +2339,8 @@ def stem(self, *args, **kwargs):
return stem_container

def pie(self, x, explode=None, labels=None, colors=None,
autopct=None, pctdistance=0.6, shadow=False,
labeldistance=1.1, startangle=None, radius=None):
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
startangle=None, radius=None, counterclock=True):
r"""
Plot a pie chart.

Expand Down Expand Up @@ -2394,6 +2394,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
*radius*: [ *None* | scalar ]
The radius of the pie, if *radius* is *None* it will be set to 1.

*counterclock*: [ *False* | *True* ]
Specify fractions direction, clockwise or counterclockwise.

The pie chart will probably look best if the figure and axes are
square, or the Axes aspect is equal. e.g.::

Expand Down Expand Up @@ -2453,13 +2456,14 @@ def pie(self, x, explode=None, labels=None, colors=None,
i = 0
for frac, label, expl in cbook.safezip(x, labels, explode):
x, y = center
theta2 = theta1 + frac
theta2 = (theta1 + frac) if counterclock else (theta1 - frac)
thetam = 2 * math.pi * 0.5 * (theta1 + theta2)
x += expl * math.cos(thetam)
y += expl * math.sin(thetam)

w = mpatches.Wedge((x, y), radius, 360. * theta1, 360. * theta2,
facecolor=colors[i % len(colors)])
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
360. * max(theta1, theta2),
facecolor=colors[i % len(colors)])
slices.append(w)
self.add_patch(w)
w.set_label(label)
Expand Down