-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG: Return null Bbox when there is no intersection for bar_label center. #25681
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
Conversation
I think this raises the more fundamental question of whether Certainly I missed that possibility when implementing #24976, so if we don't change it that type hint should be corrected, and also affects some other places where an intersection is returned directly (e.g. We in one place (internally) rely on the Falsiness of the non-overlap case. My suggestion (and I want some buy-in from other maintainers before a final decision is made, perhaps @timhoffm as API lead, in particular) would be to implement def __bool__(self):
return self.x1 >= self.x0 and self.y1 >= self.y0 This would make There are a small handful of internal checks which do I did not see any downstream packages that have similar checks, though certainly not an exhaustive search. Astropy and PIL have some Doing so at the |
@ksunden - Your proposal is quite orthogonal to the above issue. (It would open up another type of fix, but only after a deprecation period)
Since https://matplotlib.org/stable/api/transformations.html#matplotlib.transforms.BboxBase.intersection
is public API and very clear about the return value. Any user will canonically check I've no clear how widespread this is used, but would imagine that there's a bit of user code out there, that would be affected. Additional question: How is consistency across other functions returning bboxes. Do we have other cases that can return invalid boxes? If so, do they return null() or None? Overall:
|
I agree with @timhoffm 's analysis and that we should handle the wider issue independently of this PR. |
None of the below is critical, because fixing the RuntimeError is most important. But When running the code from the test I get a warning log from matplotlib/lib/matplotlib/text.py Line 725 in b86ebba
This is not helpful for the end user, but I don't know whether we can do something about it. - Does a warning from a deep burried draw() function make sense at all? Maybe we should switch to info or debug. Edge case: Setting the limit to the bar border still draws the label:
|
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.
Please rebase to latest main
to fix CI.
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.
Fair points, all around, just a thought prompted by this change.
…intersection for bar_label center.
…681-on-v3.7.x Backport PR #25681 on branch v3.7.x (BUG: Return null Bbox when there is no intersection for bar_label center.)
I tried this approach to apply some margin on the right hand side of the figure: |
PR Summary
Addresses #25625
When using
bar_label(label_type='center')
and axis limits that cut off some of the bars, an exception was raised because the Bbox intersection wasNone
. This PR makes sure the plot can still be created.PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst