Skip to content

Commit 0899015

Browse files
committed
Added center and frame arguments for pie-charts
1 parent 9891b67 commit 0899015

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

examples/pie_and_polar_charts/pie_demo_features.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"""
1919
import matplotlib.pyplot as plt
2020

21-
2221
# The slices will be ordered and plotted counter-clockwise.
2322
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
2423
sizes = [15, 30, 45, 10]
@@ -30,4 +29,31 @@
3029
# Set aspect ratio to be equal so that pie is drawn as a circle.
3130
plt.axis('equal')
3231

32+
fig = plt.figure()
33+
ax = fig.gca()
34+
import numpy as np
35+
36+
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
37+
autopct='%1.1f%%', shadow=True, startangle=90,
38+
radius=0.25, center=(0,0),frame=True)
39+
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
40+
autopct='%1.1f%%', shadow=True, startangle=90,
41+
radius=0.25, center=(1,1),frame=True)
42+
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
43+
autopct='%1.1f%%', shadow=True, startangle=90,
44+
radius=0.25, center=(0,1),frame=True)
45+
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
46+
autopct='%1.1f%%', shadow=True, startangle=90,
47+
radius=0.25, center=(1,0),frame=True)
48+
49+
ax.set_xticks([0,1])
50+
ax.set_yticks([0,1])
51+
ax.set_xticklabels(["Sunny","Cloudy"])
52+
ax.set_yticklabels(["Dry","Rainy"])
53+
ax.set_xlim((-0.5,1.5))
54+
ax.set_ylim((-0.5,1.5))
55+
56+
# Set aspect ratio to be equal so that pie is drawn as a circle.
57+
ax.set_aspect('equal')
58+
3359
plt.show()

lib/matplotlib/axes/_axes.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,8 @@ def stem(self, *args, **kwargs):
23202320
def pie(self, x, explode=None, labels=None, colors=None,
23212321
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
23222322
startangle=None, radius=None, counterclock=True,
2323-
wedgeprops=None, textprops=None):
2323+
wedgeprops=None, textprops=None, center = (0, 0),
2324+
frame=False ):
23242325
r"""
23252326
Plot a pie chart.
23262327
@@ -2330,7 +2331,8 @@ def pie(self, x, explode=None, labels=None, colors=None,
23302331
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
23312332
autopct=None, pctdistance=0.6, shadow=False,
23322333
labeldistance=1.1, startangle=None, radius=None,
2333-
counterclock=True, wedgeprops=None, textprops=None)
2334+
counterclock=True, wedgeprops=None, textprops=None,
2335+
center = (0, 0), frame = False )
23342336
23352337
Make a pie chart of array *x*. The fractional area of each
23362338
wedge is given by x/sum(x). If sum(x) <= 1, then the values
@@ -2388,6 +2390,11 @@ def pie(self, x, explode=None, labels=None, colors=None,
23882390
*textprops*: [ *None* | dict of key value pairs ]
23892391
Dict of arguments to pass to the text objects.
23902392
2393+
*center*: [ (0,0) | sequence of 2 scalars ]
2394+
Center position of the chart.
2395+
2396+
*frame*: [ *False* | *True* ]
2397+
Plot axes frame with the chart.
23912398
23922399
The pie chart will probably look best if the figure and axes are
23932400
square, or the Axes aspect is equal. e.g.::
@@ -2414,7 +2421,6 @@ def pie(self, x, explode=None, labels=None, colors=None,
24142421
:class:`~matplotlib.text.Text` instances for the numeric
24152422
labels.
24162423
"""
2417-
self.set_frame_on(False)
24182424

24192425
x = np.asarray(x).astype(np.float32)
24202426

@@ -2431,7 +2437,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
24312437
if colors is None:
24322438
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w')
24332439

2434-
center = 0, 0
2440+
24352441
if radius is None:
24362442
radius = 1
24372443

@@ -2514,10 +2520,12 @@ def pie(self, x, explode=None, labels=None, colors=None,
25142520
theta1 = theta2
25152521
i += 1
25162522

2517-
self.set_xlim((-1.25, 1.25))
2518-
self.set_ylim((-1.25, 1.25))
2519-
self.set_xticks([])
2520-
self.set_yticks([])
2523+
if not frame:
2524+
self.set_frame_on(False)
2525+
self.set_xlim((-1.25, 1.25))
2526+
self.set_ylim((-1.25, 1.25))
2527+
self.set_xticks([])
2528+
self.set_yticks([])
25212529

25222530
if autopct is None:
25232531
return slices, texts

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None,
30603060
def pie(x, explode=None, labels=None, colors=None, autopct=None,
30613061
pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,
30623062
radius=None, counterclock=True, wedgeprops=None, textprops=None,
3063-
hold=None):
3063+
hold=None,center=(0,0),frame=False):
30643064
ax = gca()
30653065
# allow callers to override the hold state by passing hold=True|False
30663066
washold = ax.ishold()
@@ -3072,7 +3072,8 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None,
30723072
autopct=autopct, pctdistance=pctdistance, shadow=shadow,
30733073
labeldistance=labeldistance, startangle=startangle,
30743074
radius=radius, counterclock=counterclock,
3075-
wedgeprops=wedgeprops, textprops=textprops)
3075+
wedgeprops=wedgeprops, textprops=textprops,
3076+
center=center,frame=frame)
30763077
draw_if_interactive()
30773078
finally:
30783079
ax.hold(washold)

0 commit comments

Comments
 (0)