Skip to content

Commit 19ab81b

Browse files
committed
Add a "radius" argument to pie drawing functions.
1 parent bd94c0d commit 19ab81b

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

doc/api/api_changes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Changes in 1.1.x
2020
will now always mean that the nearest-neighbor interpolation is performed.
2121
If you want the no-op interpolation to be performed, choose 'none'.
2222

23+
* In :meth:`~matplotlib.pyplot.pie`, one can now set the radius of the pie;
24+
setting the *radius* to 'None' (the default value), will result in a pie
25+
with a radius of 1 as before.
26+
27+
* In :meth:`~matplotlib.Axes.pie`, one can now set the radius of the pie;
28+
setting the *radius* to 'None' (the default value), will result in a pie
29+
with a radius of 1 as before.
30+
2331
* There were errors in how the tri-functions were handling input parameters
2432
that had to be fixed. If your tri-plots are not working correctly anymore,
2533
or you were working around apparent mistakes, please see issue #203 in the

examples/pylab_examples/pie_demo2.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Make a pie charts of varying size - see
3+
http://matplotlib.sf.net/matplotlib.pylab.html#-pie for the docstring.
4+
5+
This example shows a basic pie charts with labels optional features,
6+
like autolabeling the percentage, offsetting a slice with "explode"
7+
and adding a shadow, in different sizes.
8+
9+
Requires matplotlib0-0.70 or later
10+
11+
"""
12+
from pylab import *
13+
import matplotlib.gridspec as gridspec
14+
import matplotlib.pyplot as pyplot
15+
16+
17+
# Some data
18+
19+
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
20+
fracs = [15,30,45, 10]
21+
22+
explode=(0, 0.05, 0, 0)
23+
24+
25+
# Make square figures and axes
26+
27+
the_grid = matplotlib.gridspec.GridSpec(2, 2)
28+
29+
figure(1, figsize=(6,6))
30+
31+
pyplot.subplot(the_grid[0, 0])
32+
33+
pie(fracs, labels = labels, autopct = '%1.1f%%', shadow = True)
34+
35+
pyplot.subplot(the_grid[0, 1])
36+
37+
pie(fracs, explode=explode, labels = labels, autopct = '%1.1f%%', shadow = True)
38+
39+
pyplot.subplot(the_grid[1, 0])
40+
41+
pie(fracs, labels = labels, autopct = '%1.1f%%', shadow = True, radius = 0.5)
42+
43+
pyplot.subplot(the_grid[1, 1])
44+
45+
pie(fracs, explode=explode, labels = labels, autopct = '%1.1f%%', shadow = True,
46+
radius = 0.5)
47+
48+
show()

examples/tests/backend_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
'pcolor_log.py',
162162
'pcolor_small.py',
163163
'pie_demo.py',
164+
'pie_demo2.py',
164165
'plotfile_demo.py',
165166
'polar_bar.py',
166167
'polar_demo.py',

lib/matplotlib/axes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,13 +5005,14 @@ def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-',
50055005

50065006
def pie(self, x, explode=None, labels=None, colors=None,
50075007
autopct=None, pctdistance=0.6, shadow=False,
5008-
labeldistance=1.1):
5008+
labeldistance=1.1, radius=None):
50095009
r"""
50105010
Call signature::
50115011
50125012
pie(x, explode=None, labels=None,
50135013
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
5014-
autopct=None, pctdistance=0.6, labeldistance=1.1, shadow=False)
5014+
autopct=None, pctdistance=0.6, labeldistance=1.1, shadow=False,
5015+
radius=None)
50155016
50165017
Make a pie chart of array *x*. The fractional area of each
50175018
wedge is given by x/sum(x). If sum(x) <= 1, then the values
@@ -5048,6 +5049,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
50485049
*shadow*: [ *False* | *True* ]
50495050
Draw a shadow beneath the pie.
50505051
5052+
*radius*: [ *None* | scalar ]
5053+
The radius of the pie, if *radius* is *None* it will be set to 1.
5054+
50515055
The pie chart will probably look best if the figure and axes are
50525056
square. Eg.::
50535057
@@ -5084,7 +5088,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
50845088

50855089

50865090
center = 0,0
5087-
radius = 1
5091+
if radius is None: radius = 1
50885092
theta1 = 0
50895093
i = 0
50905094
texts = []

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,15 +2442,15 @@ def pcolormesh(*args, **kwargs):
24422442
# This function was autogenerated by boilerplate.py. Do not edit as
24432443
# changes will be lost
24442444
@autogen_docstring(Axes.pie)
2445-
def pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.59999999999999998, shadow=False, labeldistance=1.1000000000000001, hold=None):
2445+
def pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.59999999999999998, shadow=False, labeldistance=1.1000000000000001, radius=None, hold=None):
24462446
ax = gca()
24472447
# allow callers to override the hold state by passing hold=True|False
24482448
washold = ax.ishold()
24492449

24502450
if hold is not None:
24512451
ax.hold(hold)
24522452
try:
2453-
ret = ax.pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance)
2453+
ret = ax.pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, radius)
24542454
draw_if_interactive()
24552455
finally:
24562456
ax.hold(washold)

0 commit comments

Comments
 (0)