Skip to content

Commit 3ceade6

Browse files
committed
matplotlib#2899 Adding kwargs to pie which can handle args for both wedge and text elements separately
1 parent 3b767f6 commit 3ceade6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ def stem(self, *args, **kwargs):
23372337
def pie(self, x, explode=None, labels=None, colors=None,
23382338
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
23392339
startangle=None, radius=None, counterclock=True,
2340-
linewidth=None):
2340+
**kwargs):
23412341
r"""
23422342
Plot a pie chart.
23432343
@@ -2346,7 +2346,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
23462346
pie(x, explode=None, labels=None,
23472347
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
23482348
autopct=None, pctdistance=0.6, shadow=False,
2349-
labeldistance=1.1, startangle=None, radius=None)
2349+
labeldistance=1.1, startangle=None, radius=None,
2350+
wedgeargs={'linewidth':None}, textargs={},
2351+
)
23502352
23512353
Make a pie chart of array *x*. The fractional area of each
23522354
wedge is given by x/sum(x). If sum(x) <= 1, then the values
@@ -2446,6 +2448,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
24462448
else:
24472449
theta1 = startangle / 360.0
24482450

2451+
wedgeargs = kwargs.get('wedgeargs', {})
2452+
textargs = kwargs.get('textargs', {})
2453+
24492454
texts = []
24502455
slices = []
24512456
autotexts = []
@@ -2461,7 +2466,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
24612466
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
24622467
360. * max(theta1, theta2),
24632468
facecolor=colors[i % len(colors)],
2464-
linewidth=linewidth)
2469+
**wedgeargs)
24652470
slices.append(w)
24662471
self.add_patch(w)
24672472
w.set_label(label)
@@ -2485,7 +2490,8 @@ def pie(self, x, explode=None, labels=None, colors=None,
24852490
t = self.text(xt, yt, label,
24862491
size=rcParams['xtick.labelsize'],
24872492
horizontalalignment=label_alignment,
2488-
verticalalignment='center')
2493+
verticalalignment='center',
2494+
**textargs)
24892495

24902496
texts.append(t)
24912497

@@ -2500,9 +2506,15 @@ def pie(self, x, explode=None, labels=None, colors=None,
25002506
raise TypeError(
25012507
'autopct must be callable or a format string')
25022508

2509+
# code review request: not sure if we should pass the
2510+
# textargs to this call as well. Probably should, but
2511+
# someone who knows this better should comment.
25032512
t = self.text(xt, yt, s,
25042513
horizontalalignment='center',
2505-
verticalalignment='center')
2514+
verticalalignment='center',
2515+
**textargs)
2516+
2517+
25062518
autotexts.append(t)
25072519

25082520
theta1 = theta2

0 commit comments

Comments
 (0)