8000 Add option to rotate labels in a pie chart (#2304) by txxia · Pull Request #8217 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add option to rotate labels in a pie chart (#2304) #8217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add parameter and test
  • Loading branch information
txxia committed Mar 6, 2017
commit 7b22029d18df34c9e1e1c44d7404827ab00aa333
5 changes: 4 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
startangle=None, radius=None, counterclock=True,
wedgeprops=None, textprops=None, center=(0, 0),
frame=False):
frame=False, labelrotate=False):
r"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind converting this docstring into numpydoc? It will make it much more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy to, do you want me to create a separate issue for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's do this. I am going to merge this PR straight away, as everything is fine!

Plot a pie chart.

10000 Expand Down Expand Up @@ -2542,6 +2542,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
*frame*: [ *False* | *True* ]
Plot axes frame with the chart.

*labelrotate*: [ *False* | *True* ]
Rotate each label to the angle of the corresponding slice.

The pie chart will probably look best if the figure and axes are
square, or the Axes aspect is equal. e.g.::

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3208,7 +3208,7 @@ def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None,
def pie(x, explode=None, labels=None, colors=None, autopct=None,
pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,
radius=None, counterclock=True, wedgeprops=None, textprops=None,
center=(0, 0), frame=False, hold=None, data=None):
center=(0, 0), frame=False, labelrotate=False, hold=None, data=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that file autogenerated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the changes on this file are generated by boilerplate.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as you haven't manually updated this file, it's all good :)

ax = gca()
# Deprecated: allow callers to override the hold state
# by passing hold=True|False
Expand All @@ -3225,7 +3225,7 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None,
labeldistance=labeldistance, startangle=startangle,
radius=radius, counterclock=counterclock,
wedgeprops=wedgeprops, textprops=textprops, center=center,
frame=frame, data=data)
frame=frame, labelrotate=labelrotate, data=data)
finally:
ax._hold = washold

Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4241,6 +4241,19 @@ def test_pie_frame_grid():
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')

@image_comparison(baseline_images=['pie_ccw_true'], extensions=['png'])
def test_pie_label_rotate():
# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')

plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90,
labelrotate=True)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')

@image_comparison(baseline_images=['set_get_ticklabels'], extensions=['png'])
def test_set_get_ticklabels():
Expand Down
0