Skip to content

Commit b430b74

Browse files
committed
add parameter and test
1 parent 8101c8a commit b430b74

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
24752475
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
24762476
startangle=None, radius=None, counterclock=True,
24772477
wedgeprops=None, textprops=None, center=(0, 0),
2478-
frame=False):
2478+
frame=False, labelrotate=False):
24792479
r"""
24802480
Plot a pie chart.
24812481
@@ -2542,6 +2542,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
25422542
*frame*: [ *False* | *True* ]
25432543
Plot axes frame with the chart.
25442544
2545+
*labelrotate*: [ *False* | *True* ]
2546+
Rotate each label to the angle of the corresponding slice.
2547+
25452548
The pie chart will probably look best if the figure and axes are
25462549
square, or the Axes aspect is equal. e.g.::
25472550

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,7 +3208,7 @@ def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None,
32083208
def pie(x, explode=None, labels=None, colors=None, autopct=None,
32093209
pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,
32103210
radius=None, counterclock=True, wedgeprops=None, textprops=None,
3211-
center=(0, 0), frame=False, hold=None, data=None):
3211+
center=(0, 0), frame=False, labelrotate=False, hold=None, data=None):
32123212
ax = gca()
32133213
# Deprecated: allow callers to override the hold state
32143214
# by passing hold=True|False
@@ -3225,7 +3225,7 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None,
32253225
labeldistance=labeldistance, startangle=startangle,
32263226
radius=radius, counterclock=counterclock,
32273227
wedgeprops=wedgeprops, textprops=textprops, center=center,
3228-
frame=frame, data=data)
3228+
frame=frame, labelrotate=labelrotate, data=data)
32293229
finally:
32303230
ax._hold = washold
32313231

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,6 +4241,19 @@ def test_pie_frame_grid():
42414241
# Set aspect ratio to be equal so that pie is drawn as a circle.
42424242
plt.axis('equal')
42434243

4244+
@image_comparison(baseline_images=['pie_ccw_true'], extensions=['png'])
4245+
def test_pie_label_rotate():
4246+
# The slices will be ordered and plotted counter-clockwise.
4247+
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
4248+
sizes = [15, 30, 45, 10]
4249+
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
4250+
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
4251+
4252+
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
4253+
autopct='%1.1f%%', shadow=True, startangle=90,
4254+
labelrotate=True)
4255+
# Set aspect ratio to be equal so that pie is drawn as a circle.
4256+
plt.axis('equal')
42444257

42454258
@image_comparison(baseline_images=['set_get_ticklabels'], extensions=['png'])
42464259
def test_set_get_ticklabels():

0 commit comments

Comments
 (0)