-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adds normalize kwarg to pie function #16985
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
Conversation
WRT context, please give your PRs and commit messages more context. One should not have to look up #16905 to understand what a commit does. |
Because you are changing the signature of an Axes method, you will also need to re-run |
Thanks for working on this. It looks like it is headed in the right direction! |
There are some style issues, see the flake8 run on travis:
Also, please run |
I've fixed the flake8 issues and also ran boilerplate.py in the previous commit. Please tell if there's any problem regarding the boilerplate. |
@raphacosta27 Could you please squash your commits? If you do so you will need to force-push to github (and ignore it's suggestion to run |
Hi there, I've fixed the previous suggested comments but I am with problem squashing the commits, but will solve it tomorrow probably. |
If you need help with git drop into the gitter channel (https://gitter.im/matplotlib/matplotlib) |
1b2eced
to
dedc7f6
Compare
I think the squash is done by now. Git said that I had some conflicting with the behaviour.rst file but I've already fixed it. Thanks. |
@raphacosta27 is it ok, if I force-push to your branch to clean this up? |
Sure, no problem! Go ahead. |
lib/matplotlib/axes/_axes.py
Outdated
@@ -2942,6 +2942,17 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
shadow : bool, default: False | ||
Draw a shadow beneath the pie. | ||
|
||
normalize: None or bool, default: None | ||
``pie()`` used to draw a partial pie if ``sum(x) < 1``. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to state what normalize
does first, and then the deprecated information in a second paragraph?
lib/matplotlib/axes/_axes.py
Outdated
if normalize is None: | ||
if sx < 1: | ||
cbook.warn_deprecated( | ||
"3.1", message="normalize=None does not normalize if " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.3, not 3.1
lib/matplotlib/axes/_axes.py
Outdated
"3.1", message="normalize=None does not normalize if " | ||
"the sum is less than 1 " | ||
"but this behavior is deprecated " | ||
"since %(since)s. After the deprecation period " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use %(removal)s
to indicate when the deprecation period is over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to changes, but it needs a rebase. I will try to take care of that later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm overall thumbs up on this change, but think that the behavior in the case where normalize = False
and the total adds up to more than a full pie too easily hides bugs where the user didn't mean to have sx > 1
.
However, since the user is specifically setting normalize = False
, I would be content with adding a comment to the docstring that warns the user that we don't guarantee the plot will "make sense" if they pass normalize = False
and sx > 1
.
lib/matplotlib/axes/_axes.py
Outdated
normalize: None or bool, default: None | ||
When *True*, always make a full pie by normalizing x so that | ||
``sum(x) == 1``. When *False*, make a partial pie. | ||
When *None*, gives the current behavior and warns if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "current behavior", this should describe the behavior explicitly (since that will now be the "previous" behavior).
else: | ||
normalize = True | ||
if normalize: | ||
x = x / sx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if normalize = False and sx > 1
? Unlike normalize = False and sx < 1
(which will look the same as the old behavior), we don't have any precedent for what the output should look like. To me, it doesn't make sense to make a pie plot that that more than 100%, since some of the pies will overlap each other (making it look like a normal pie plot, but where some of the slices look the incorrect size).
I think it would be less surprising to the user if we fail when asked to make pie plots with normalize = False and sz > 1
.
normalize = False and sx < 1
, a partial pie, this is existing behavior.normalize = False and sx > 1
, more than a full pie....it's not clear to me what this should look like once drawn....and it's new behaviornormalize = True and sx >= 1
, the old behavior is unchanged....normalize = True and sz < 1
, the new behavior, I definitely like this being built-in topie
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recently made some changes to pie
to not accept negative values (which also resulted in a greater-than-full pie),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL. I guess it's part of the pie now.
@raphacosta27 I took the liberty of rebasing, attempting to address the documentation concerns, and force-pushed to your branch. |
Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy edits for the description of the None case and highly optional suggestion for how to shorten and reduce redundancy of the language in the docstring's deprecation warning.
This could really use an example somewhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to @brunobeltran suggestions, please add an example of the kwargs use, perhaps to a previous pie
example.
Co-authored-by: Bruno Beltran <brunobeltran0@gmail.com>
Co-authored-by: Bruno Beltran <brunobeltran0@gmail.com>
Since I'd like to get this into 3.3, I've taken the liberty to push the changes requested by @brunobeltran. @jklymak While examples are always nice, I wouldn't block on that. We haven't had an example for |
Yeah, but the new behaviour is complicated enough it would greatly benefit from one that could be linked in the API docs. |
I don't think the behavior is complicated: If It may look more complicated because of the deprecation. |
I know what "partial pie" means from reading this PR, but not from reading the docstring. |
@jklymak If you have suggestions how to improve the docs, we can always update. |
PR Summary
pie() used to draw a partial pie if the sum of the values was < 1 and already normalized the values if the sum was > 1. I added a kwarg normalize into pie function and deprecated the previous behaviour. Now, the function will always normalize the values to a full pie by default. If one wants to draw a partial pie, one should pass normalize=False explicitly.
PR Checklist