-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make API of get_tightbbox more consistent between Axes and Axis. #17287
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
lib/matplotlib/axes/_base.py
Outdated
try: | ||
bb_yaxis = self.yaxis.get_tightbbox(renderer, ignore_label=igl) | ||
bb_yaxis = self.yaxis.get_tightbbox( |
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.
Oops!
@@ -1079,15 +1079,15 @@ def _get_tick_bboxes(self, ticks, renderer): | |||
[tick.label2.get_window_extent(renderer) | |||
for tick in ticks if tick.label2.get_visible()]) | |||
|
|||
def get_tightbbox(self, renderer, *, ignore_label=None): | |||
def get_tightbbox(self, renderer, *, for_layout_only=False): |
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.
I'm 50/50 on this change. Consistency is nice, OTOH, the kwarg name doesn't make a lot of sense at this level. But since the docs refer to *_layout maybe its OK.
bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5 | ||
bb.y1 = bb.y0 + 1.0 | ||
if for_layout_only: | ||
if self.axis_name == "x" and bb.width > 0: |
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.
... and I guess I still don't particularly like the introspection. But, again if other folks think the consistency is more important than explicitness I won't block.
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.
Maybe a bit of paranoia here with axis_name = getattr(self, 'axis_name', '')
?
Instead of having Axes trying to figure out what direction to ignore, let the Axis handle that. This keeps the signature of get_tightbbox consistent between Axes and Axis. Also fix a typo bb_xaxis -> bb_yaxis.
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.
I guess this is fine.
The I am 👍 on making more use of that introspection. I'm +0.75 on the new name. It is less explicit about what it is doing, but it is more explicit about why it is doing it. |
Added the change in #16981 (comment) as a separate commit. |
Instead of having Axes trying to figure out what direction to ignore,
let the Axis handle that. This keeps the signature of get_tightbbox
consistent between Axes and Axis.
Also fix a typo bb_xaxis -> bb_yaxis.
Followup to #17222; was discussed briefly in #17222 (comment) though not acted upon. Even if we decide not to go that route at least the bb_xaxis->bb_yaxis change should be split out and merged for 3.3.
Marked as release critical so that we don't change the API after the release, if we decide to go this route.
PR Summary
PR Checklist