Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a0c448

Browse files
committed
Add pie startangle kwarg to demo, and add direction info to docstring
1 parent d67d93f commit 6a0c448

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

examples/pylab_examples/pie_demo.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
http://matplotlib.sf.net/matplotlib.pylab.html#-pie for the docstring.
44
55
This example shows a basic pie chart with labels optional features,
6-
like autolabeling the percentage, offsetting a slice with "explode"
7-
and adding a shadow.
8-
9-
Requires matplotlib0-0.70 or later
6+
like autolabeling the percentage, offsetting a slice with "explode",
7+
adding a shadow, and changing the starting angle.
108
119
"""
1210
from pylab import *
@@ -15,11 +13,18 @@
1513
figure(1, figsize=(6,6))
1614
ax = axes([0.1, 0.1, 0.8, 0.8])
1715

16+
# The slices will be ordered and plotted counter-clockwise.
1817
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
19-
fracs = [15,30,45, 10]
20-
18+
fracs = [15, 30, 45, 10]
2119
explode=(0, 0.05, 0, 0)
22-
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
20+
21+
pie(fracs, explode=explode, labels=labels,
22+
autopct='%1.1f%%', shadow=True, startangle=90)
23+
# The default startangle is 0, which would start
24+
# the Frogs slice on the x-axis. With startangle=90,
25+
# everything is rotated counter-clockwise by 90 degrees,
26+
# so the plotting starts on the positive y-axis.
27+
2328
title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
2429

2530
show()

lib/matplotlib/axes.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5017,7 +5017,8 @@ def pie(self, x, explode=None, labels=None, colors=None,
50175017
Make a pie chart of array *x*. The fractional area of each
50185018
wedge is given by x/sum(x). If sum(x) <= 1, then the values
50195019
of x give the fractional area directly and the array will not
5020-
be normalized.
5020+
be normalized. The wedges are plotted counterclockwise,
5021+
by default starting from the x-axis.
50215022
50225023
Keyword arguments:
50235024
@@ -5051,7 +5052,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
50515052
50525053
*startangle*: [ *None* | Offset angle ]
50535054
If not *None*, rotates the start of the pie chart by *angle*
5054-
degrees.
5055+
degrees counterclockwise from the x-axis.
50555056
50565057
The pie chart will probably look best if the figure and axes are
50575058
square. Eg.::
@@ -5097,7 +5098,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
50975098
theta1 = 0
50985099
else:
50995100
theta1 = startangle / 360.0
5100-
5101+
51015102
texts = []
51025103
slices = []
51035104
autotexts = []
@@ -5162,8 +5163,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
51625163
self.set_xticks([])
51635164
self.set_yticks([])
51645165

5165-
if autopct is None: return slices, texts
5166-
else: return slices, texts, autotexts
5166+
if autopct is None:
5167+
return slices, texts
5168+
else:
5169+
return slices, texts, autotexts
51675170

51685171
@docstring.dedent_interpd
51695172
def errorbar(self, x, y, yerr=None, xerr=None,

0 commit comments

Comments
 (0)