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

Conversation

txxia
Copy link
Contributor

@txxia txxia commented Mar 7, 2017

Fixes #2304
I add the flag labelrotate=True, it should fix the problem in most cases.
For pie chart with too many sections, I think using leader lines should be a better solution.

@txxia txxia changed the title Fix #2304 Fix issue #2304 Mar 7, 2017
@txxia txxia changed the title Fix issue #2304 Add option to rotate labels in a pie chart (#2304) Mar 7, 2017
Copy link
Member

@phobson phobson left a comment

Choose a reason for hiding this comment

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

Thanks for the thorough and well-tested PR!

@dstansby dstansby added this to the 2.1 (next point release) milestone Mar 7, 2017
@@ -2640,11 +2644,15 @@ def get_next_color():
xt = x + labeldistance * radius * math.cos(thetam)
yt = y + labeldistance * radius * math.sin(thetam)
label_alignment = xt > 0 and 'left' or 'right'
label_rotation = 'horizontal'
if labelrotate:
label_rotation = thetamd + (0 if xt > 0 else 180)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using thetamd I think it would be better to just use np.rad2deg(thetam)

@dstansby
Copy link
Member

dstansby commented Mar 7, 2017

This looks really good, thanks for the PR!

I think rotatelabels might be a better name for the argument (saying rotatelabels == False as an English sentence makes more sense to me instead of labelrotate == False)

@txxia txxia changed the title Add option to rotate labels in a pie chart (#2304) [WIP] Add option to rotate labels in a pie chart (#2304) Mar 7, 2017
@txxia
Copy link
Contributor Author

txxia commented Mar 7, 2017

Just noticed vertical alignment needs to be updated as well, it should be fixed now.

@txxia txxia changed the title [WIP] Add option to rotate labels in a pie chart (#2304) Add option to rotate labels in a pie chart (#2304) Mar 7, 2017
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

This looks good now, thanks for the work! I will merge if/when travis and appveyor tests pass.

@dstansby dstansby self-assigned this Mar 8, 2017
@dstansby
Copy link
Member

dstansby commented Mar 8, 2017

It looks like there's a PEP8 violation: https://travis-ci.org/matplotlib/matplotlib/jobs/208805540#L1676 - other than that the travis tests seem fine.

@txxia
Copy link
Contributor Author

txxia commented Mar 8, 2017

Thanks!
It seems that pep8 failure was caused by someone else: 856b747
Failure message from Travis:

/home/travis/build/matplotlib/matplotlib/examples/mplot3d/polys3d_demo.py:6:69: W291 trailing whitespace
Demonstrate how to create polygons which fill the space under a line

@dstansby
Copy link
Member

dstansby commented Mar 8, 2017

Ugh, sorry, I should have noticed that - thanks for pointing it out. I'll fix that myself and merge this pull request when I've done that.

@@ -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):
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 :)

@@ -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, rotatelabels=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!

@NelleV NelleV merged commit 296bc4f into matplotlib:master Mar 11, 2017
@NelleV
Copy link
Member

NelleV commented Mar 11, 2017

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an argument rotate_labels to pie chart
4 participants