Skip to content

Raise an ValueError when Axes.pie accepts negative values #15923 #15935

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 2 commits into from
Dec 14, 2019

Conversation

Inception95
Copy link
Contributor

@Inception95 Inception95 commented Dec 14, 2019

PR Summary

Issue #15923
Axes.pie accepts negative values which outputs the wrong pie chart. This issue is caused by not checking the positive and negative of all input wedge sizes of "x" in Axes.pie.

Now it will raise a ValueError, which indicates wedge sizes should be non-negative when feeding negative values into Axes.pie. It is done by adding an if condition right before calculating the portion of all sizes in the "x" `array.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@@ -2921,6 +2921,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
"and will be removed %(removal)s; pass a 1D array instead.")
x = np.atleast_1d(x.squeeze())

for part in x:
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use np.any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, np.any(x<0) is neater!

@jklymak
Copy link
Member

jklymak commented Dec 14, 2019

Thanks for the PR. This should probably get a test as well...

@Inception95
Copy link
Contributor Author

@jklymak Sure, I will add the test.

@jklymak jklymak added this to the v3.3.0 milestone Dec 14, 2019
@anntzer
Copy link
Contributor

anntzer commented Dec 14, 2019

Thanks for you contribution, hoping to see you around again :)

@anntzer anntzer merged commit b12c761 into matplotlib:master Dec 14, 2019
@Inception95
Copy link
Contributor Author

@anntzer Happy to help! Thanks for this great opportunity.

@Inception95 Inception95 deleted the pie_takes_negative_values branch December 14, 2019 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants