8000 Bugfix for issue 16501 raised ValueError polar subplot with (thetamax - thetamin) > 2pi by prasadve · Pull Request #16717 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Bugfix for issue 16501 raised ValueError polar subplot with (thetamax - thetamin) > 2pi #16717

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 7 commits into from
Apr 19, 2020

Conversation

prasadve
Copy link
Contributor
@prasadve prasadve commented Mar 10, 2020

PR Summary

Recopy of old PR: #16711.
This PR addresses issue #16501 set_thetalim takes in parameters as radians or degrees but the problem occurs when the range or difference between the parameters is large than 2pi radians or larger than 360 in terms of degrees. The polar subplot will produce a deformed graph as it is shown in the Github issue 16501.

Fix: The fix was done using a check for ranges larger than 2pi, and if so ValueError is raised

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

if 'thetamin' in kwargs:
kwargs['xmin'] = np.deg2rad(kwargs.pop('thetamin'))
thetamin = np.deg2rad(kwargs.pop('thetamin'))
Copy link
Member

Choose a reason for hiding this comment

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

Is all this argument dance because we have to check the generic *args, *kwargs signature? If so, we should parse to that thetamax and thetamin, check that once and pass it to set_xlim() explicitly.

Later on, we should make the method signature explicit, which will simplify the check. Ideally, one would to this before adding the check, but since that will involve an API-change with a deprecation period, we would not be able to add the simplified check for the next to minor releases. So the more complex check is necessary for now.

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 if statements there are to check the possible signatures. The signatures allowed for set_thetalim are as follows:

  1. set_thetalim(minval, maxval): Set the limits in radians.
  2. set_thetalim(thetamin=minval, thetamax=maxval): Set the limits in degrees.
    These were taken straight out of the documentation for function set_thetalim.

By "If, so we should parse to that thetamax and thetamin, check that once and pass it to set_xlim() explicitly" do you mean signature 1 ( radians ) would not be used anymore?

Copy link
Member

Choose a reason for hiding this comment

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

Ultimately (unless we decide to change the awkward rad/degree API altogether) we could at least do def set_thetalim(min_rad, max_rad, /, *, thetamin, thetamax), which is more explicit but has the exact same semantics in terms of positional and keyword arguements. But that would have to wait until the min. supported Python version is 3.8, which introduced the positional-only arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for this change I have made changes. Made an explicit call to set_xlim using parameter thetamin, thetamax, left and right. Please let me know if further changes need to be made. I do agree making the set_thetalim explicit in the future when 3.8 rolls out.

Copy link
Member

Choose a reason for hiding this comment

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

Passing the parameters on consistently and checking them on the go is surprisingly complex. This code covers the documented API versions using two kwargs or two positional args. It does not catch all edge cases like set_thetalim(0, thetamax=180 which technically works as well.

I'll think about this but I think that's ok.

I'd move these theta parsing down so that you have the order

  • args parsing
  • args checks
  • theta parsing
  • theta checks

@tacaswell tacaswell added this to the v3.3.0 milestone Mar 30, 2020
if 'thetamin' in kwargs:
kwargs['xmin'] = np.deg2rad(kwargs.pop('thetamin'))
thetamin = np.deg2rad(kwargs.pop('thetamin'))
Copy link
Member

Choose a reason for hiding this comment

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

Passing the parameters on consistently and checking them on the go is surprisingly complex. This code covers the documented API versions using two kwargs or two positional args. It does not catch all edge cases like set_thetalim(0, thetamax=180 which technically works as well.

I'll think about this but I think that's ok.

I'd move these theta parsing down so that you have the order

  • args parsing
  • args checks
  • theta parsing
  • theta checks

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.

Thanks for the contribution!

@dstansby dstansby merged commit 29aae1f into matplotlib:master Apr 19, 2020
@anntzer anntzer mentioned this pull request Apr 19, 2020
6 tasks
@prasadve
Copy link
Contributor Author

@dstansby np glad we could help!!

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.

4 participants
0