-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
""" | ||
Return a bounding box that encloses the axis. It only accounts | ||
tick labels, axis label, and offsetText. | ||
|
||
If ``ignore_label`` is 'x', then the width of the label is collapsed | ||
to near zero. If 'y', then the height is collapsed to near zero. This | ||
is for tight/constrained_layout to be able to ignore too-long labels | ||
when doing their layout. | ||
If *for_layout_only* is True, then the width of the label (if this | ||
is an x-axis) or the height of the label (if this is a y-axis) is | ||
collapsed to near zero. This allows tight/constrained_layout to ignore | ||
too-long labels when doing their layout. | ||
""" | ||
if not self.get_visible(): | ||
return | ||
|
@@ -1114,14 +1114,15 @@ def get_tightbbox(self, renderer, *, ignore_label=None): | |
if self.label.get_visible(): | ||
bb = self.label.get_window_extent(renderer) | ||
# for constrained/tight_layout, we want to ignore the label's | ||
# width because the adjustments they make can't be improved. | ||
# width/height because the adjustments they make can't be improved. | ||
# this code collapses the relevant direction | ||
if ignore_label == 'x' and bb.width > 0: | ||
bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5 | ||
bb.x1 = bb.x0 + 1.0 | ||
elif ignore_label == 'y' and bb.height > 0: | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a bit of paranoia here with |
||
bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5 | ||
bb.x1 = bb.x0 + 1.0 | ||
if self.axis_name == "y" and bb.height > 0: | ||
bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5 | ||
bb.y1 = bb.y0 + 1.0 | ||
bboxes.append(bb) | ||
bboxes = [b for b in bboxes | ||
if 0 < b.width < np.inf and 0 < b.height < np.inf] | ||
|
Uh oh!
There was an error while loading. Please reload this page.