MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / get_tightbbox

Method get_tightbbox

lib/matplotlib/axis.py:1411–1459  ·  view source on GitHub ↗

Return a bounding box that encloses the axis. It only accounts tick labels, axis label, and offsetText. 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 zer

(self, renderer=None, *, for_layout_only=False)

Source from the content-addressed store, hash-verified

1409 if tick.label2.get_visible() and tick.label2.get_in_layout()])
1410
1411 def get_tightbbox(self, renderer=None, *, for_layout_only=False):
1412 """
1413 Return a bounding box that encloses the axis. It only accounts
1414 tick labels, axis label, and offsetText.
1415
1416 If *for_layout_only* is True, then the width of the label (if this
1417 is an x-axis) or the height of the label (if this is a y-axis) is
1418 collapsed to near zero. This allows tight/constrained_layout to ignore
1419 too-long labels when doing their layout.
1420 """
1421 if not self.get_visible() or for_layout_only and not self.get_in_layout():
1422 return
1423 if renderer is None:
1424 renderer = self.get_figure(root=True)._get_renderer()
1425 ticks_to_draw = self._update_ticks()
1426
1427 self._update_label_position(renderer)
1428
1429 # go back to just this axis's tick labels
1430 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1431
1432 self._update_offset_text_position(tlb1, tlb2)
1433 self.offsetText.set_text(self.major.formatter.get_offset())
1434
1435 bboxes = [
1436 *(a.get_window_extent(renderer)
1437 for a in [self.offsetText]
1438 if a.get_visible()),
1439 *tlb1, *tlb2,
1440 ]
1441 # take care of label
1442 if self.label.get_visible():
1443 bb = self.label.get_window_extent(renderer)
1444 # for constrained/tight_layout, we want to ignore the label's
1445 # width/height because the adjustments they make can't be improved.
1446 # this code collapses the relevant direction
1447 if for_layout_only:
1448 if self.axis_name == "x" and bb.width > 0:
1449 bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5
1450 bb.x1 = bb.x0 + 1.0
1451 if self.axis_name == "y" and bb.height > 0:
1452 bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5
1453 bb.y1 = bb.y0 + 1.0
1454 bboxes.append(bb)
1455 bboxes = [b for b in bboxes if b._is_finite()]
1456 if bboxes:
1457 return mtransforms.Bbox.union(bboxes)
1458 else:
1459 return None
1460
1461 def get_tick_padding(self):
1462 values = []

Callers

nothing calls this directly

Calls 13

_update_ticksMethod · 0.95
_get_ticklabel_bboxesMethod · 0.95
get_in_layoutMethod · 0.80
_is_finiteMethod · 0.80
unionMethod · 0.80
get_visibleMethod · 0.45
_get_rendererMethod · 0.45
get_figureMethod · 0.45
set_textMethod · 0.45
get_offsetMethod · 0.45

Tested by

no test coverage detected