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

Function reposition_axes

lib/matplotlib/_constrained_layout.py:645–684  ·  view source on GitHub ↗

Reposition all the Axes based on the new inner bounding box.

(layoutgrids, fig, renderer, *,
                    w_pad=0, h_pad=0, hspace=0, wspace=0, compress=False)

Source from the content-addressed store, hash-verified

643
644
645def reposition_axes(layoutgrids, fig, renderer, *,
646 w_pad=0, h_pad=0, hspace=0, wspace=0, compress=False):
647 """
648 Reposition all the Axes based on the new inner bounding box.
649 """
650 trans_fig_to_subfig = fig.transFigure - fig.transSubfigure
651 for sfig in fig.subfigs:
652 bbox = layoutgrids[sfig].get_outer_bbox()
653 sfig._redo_transform_rel_fig(
654 bbox=bbox.transformed(trans_fig_to_subfig))
655 reposition_axes(layoutgrids, sfig, renderer,
656 w_pad=w_pad, h_pad=h_pad,
657 wspace=wspace, hspace=hspace, compress=compress)
658
659 for ax in fig._localaxes:
660 if ax.get_subplotspec() is None or not ax.get_in_layout():
661 continue
662
663 # grid bbox is in Figure coordinates, but we specify in panel
664 # coordinates...
665 ss = ax.get_subplotspec()
666 gs = ss.get_gridspec()
667 if gs not in layoutgrids:
668 return
669
670 bbox = layoutgrids[gs].get_inner_bbox(rows=ss.rowspan,
671 cols=ss.colspan)
672
673 # transform from figure to panel for set_position:
674 newbbox = trans_fig_to_subfig.transform_bbox(bbox)
675 ax._set_position(newbbox)
676
677 # move the colorbars:
678 # we need to keep track of oldw and oldh if there is more than
679 # one colorbar:
680 offset = {'left': 0, 'right': 0, 'bottom': 0, 'top': 0}
681 for nn, cbax in enumerate(ax._colorbars[::-1]):
682 if ax == cbax._colorbar_info['parents'][0]:
683 reposition_colorbar(layoutgrids, cbax, renderer,
684 offset=offset, compress=compress)
685
686
687def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None, compress=False):

Callers 1

do_constrained_layoutFunction · 0.85

Calls 10

reposition_colorbarFunction · 0.85
get_outer_bboxMethod · 0.80
get_in_layoutMethod · 0.80
get_inner_bboxMethod · 0.80
transform_bboxMethod · 0.80
_set_positionMethod · 0.80
transformedMethod · 0.45
get_subplotspecMethod · 0.45
get_gridspecMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…