Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improve error message for gridspec when the index is not an integer. #24630

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 6, 2022

Conversation

ShawnZhong
Copy link
Contributor

PR Summary

plt.subplot(1, 2, 0.5) raises ValueError: num must be 1 <= num <= 2, not 0.5, which is not so useful.

This PR changes it to report Subplot specifier must be an integer, not 0.5

PR Checklist

Documentation and Tests

  • [N/A] Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Thanks! Makes sense.

(For future PRs, please create a separate branch. It will be easier in the long run if PRs needs updating etc.)

@@ -599,7 +599,10 @@ def _from_subplot_args(figure, args):
)
i, j = num
else:
if not isinstance(num, Integral) or num < 1 or num > rows*cols:
Copy link
Contributor

Choose a reason for hiding this comment

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

I would slightly prefer making the previous error message more complete, e.g. "num must be an integer with 1 <= num <= ..., not ...", instead of delivering the info in a piecemeal fashion. (If I accidentally pass 0.5 this will help me fixing the entire error (both type and value) at once, rather than first slapping an int() call, re-running the code, and seeing the second error.)

Copy link
Member

Choose a reason for hiding this comment

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

I also have a slight preference for a single more verbose error error message.

@tacaswell tacaswell merged commit f285c3f into matplotlib:main Dec 6, 2022
@tacaswell
Copy link
Member

Thank you and congratulations on your first merged Matplotlib PR @ShawnZhong 🎉

I hope we hear from you again!

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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.