Skip to content

Skip arrow annotations with nonfinite text positions - #32620

Open
ada-wh525 wants to merge 1 commit into
matplotlib:mainfrom
ada-wh525:ada-wh525/annotation-nonfinite-position
Open

ada-wh525 wants to merge 1 commit into
matplotlib:mainfrom
ada-wh525:ada-wh525/annotation-nonfinite-position

Conversation

@ada-wh525

Copy link
Copy Markdown

PR summary

Drawing an arrow annotation can raise StopIteration if its text position maps to nonfinite display coordinates. For example, (0, 0) is finite in polar coordinates, but its display position is undefined when the lower radial limit is 0.25.

This change checks the text position in display coordinates and skips the annotation when that position is nonfinite. Moving the same annotation back to a valid position makes it visible again.

The regression tests cover an explicit NaN on Cartesian axes and a finite position on polar axes that becomes invalid after transformation. Both cases failed on main before the fix. The focused test run had 240 passes and 54 skips. PNG, SVG, and PDF exports were also checked locally.

Closes #29516

AI Disclosure

OpenAI Codex helped to wrote the implementation and regression tests, ran the local checks, and helped translate this description.

PR quality check

  • Use an expressive title
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

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

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

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

@github-actions github-actions Bot added first-contribution topic: text AgentScan: mixed AgentScan detected an account with mixed automation signals. and removed first-contribution labels Nov 18, 2026
@iccir iccir removed the AgentScan: mixed AgentScan detected an account with mixed automation signals. label Nov 18, 2026
@story645

story645 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

and skips the annotation when that position is nonfinite

I'm wary of silent failures, especially when it's a mistake I could see myself making. Is it viable to error out instead?

ETA: also thanks for catching this!

@ada-wh525 ada-wh525 closed this Nov 19, 2026
@ada-wh525 ada-wh525 reopened this Nov 19, 2026
@ada-wh525

ada-wh525 commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

and skips the annotation when that position is nonfinite

I'm wary of silent failures, especially when it's a mistake I could see myself making. Is it viable to error out instead?

ETA: also thanks for catching this!

Yes, I think we could raise a ValueError. I agree it would be confusing for an arrow to disappear without any indication that xytext contains NaN. Would a warning work in that case? It could point the user to xytext while still letting the rest of the figure render.

so how about we keep the original polar example quiet. There, xytext=(0, 0) is finite and only becomes undefined in display coordinates when the radial lower limit is set to 0.25. I’d skip the annotation without a warning for that draw, so it can reappear when the limits include the origin again.

This branch has not been deployed

No deployments
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.

[Bug]: Cannot draw arrow from polar plot origin after setting rticks

4 participants