-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
adding check_xytext for NaN values #30381
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
base: main
Are you sure you want to change the base?
adding check_xytext for NaN values #30381
Conversation
lib/matplotlib/text.py
Outdated
return valid | ||
|
||
if all(isinstance(xyt, numbers.Number) for xyt in self.xytext): | ||
valid = not np.isnan(self.xytext).any() and np.isfinite(self.xytext).all() |
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 fix the polar case, you need to check these values after they are transformed to "screen space", for which you can use self.axes.transData.transform
. See the Transforms Tutorial for more details.
I'm not really sure if invalid values here should make the annotation invisible or raise a more helpful error message.
Ok, I will take a look at it later. And I agree that not drawing the annotation isn't the best behaviour but it's how it works for check_xy and I wanted to keep it similar, maybe an error message for both would be better |
|
PR summary
Closes #29516 , I have a few things to address here, this PR fixes errors for this type of case:
It checks that the coordinates for xytext are a finite number, and if it isn't, the text and the arrow are not drawn, same behaviour as check_xy.
I wasn't able to reproduce the first error in the thread in a similar environment, and for this other piece of code:
the error seems to be related to set_ylim, if you remove that, it works. Also, if you change the y coordinate for xy to be less than ylim's bottom, for example:
it seems to work for anything < ylim's bottom (.25 in this case), so I guess the error appears when the text is supposed to be visible, this behaviour is weird and the easiest solution I can think of is just to not apply/allow ylim because it doesn't do anything in polar coordinates, but I don't have enough context to know if that's a good idea or even possible so I would like feedback on that 🙂.
PR checklist