MCPcopy
hub / github.com/matplotlib/matplotlib / do_constrained_layout

Function do_constrained_layout

lib/matplotlib/_constrained_layout.py:63–154  ·  view source on GitHub ↗

Do the constrained_layout. Called at draw time in ``figure.constrained_layout()`` Parameters ---------- fig : `~matplotlib.figure.Figure` `.Figure` instance to do the layout in. h_pad, w_pad : float Padding around the Axes elements in figure-normalized unit

(fig, h_pad, w_pad,
                          hspace=None, wspace=None, rect=(0, 0, 1, 1),
                          compress=False)

Source from the content-addressed store, hash-verified

61
62######################################################
63def do_constrained_layout(fig, h_pad, w_pad,
64 hspace=None, wspace=None, rect=(0, 0, 1, 1),
65 compress=False):
66 """
67 Do the constrained_layout. Called at draw time in
68 ``figure.constrained_layout()``
69
70 Parameters
71 ----------
72 fig : `~matplotlib.figure.Figure`
73 `.Figure` instance to do the layout in.
74
75 h_pad, w_pad : float
76 Padding around the Axes elements in figure-normalized units.
77
78 hspace, wspace : float
79 Fraction of the figure to dedicate to space between the
80 Axes. These are evenly spread between the gaps between the Axes.
81 A value of 0.2 for a three-column layout would have a space
82 of 0.1 of the figure width between each column.
83 If h/wspace < h/w_pad, then the pads are used instead.
84
85 rect : tuple of 4 floats
86 Rectangle in figure coordinates to perform constrained layout in
87 [left, bottom, width, height], each from 0-1.
88
89 compress : bool
90 Whether to shift Axes so that white space in between them is
91 removed. This is useful for simple grids of fixed-aspect Axes (e.g.
92 a grid of images).
93
94 Returns
95 -------
96 layoutgrid : private debugging structure
97 """
98
99 renderer = fig._get_renderer()
100 # make layoutgrid tree...
101 layoutgrids = make_layoutgrids(fig, None, rect=rect)
102 if not layoutgrids['hasgrids']:
103 _api.warn_external('There are no gridspecs with layoutgrids. '
104 'Possibly did not call parent GridSpec with the'
105 ' "figure" keyword')
106 return
107
108 for _ in range(2):
109 # do the algorithm twice. This has to be done because decorations
110 # change size after the first re-position (i.e. x/yticklabels get
111 # larger/smaller). This second reposition tends to be much milder,
112 # so doing twice makes things work OK.
113
114 # make margins for all the Axes and subfigures in the
115 # figure. Add margins for colorbars...
116 make_layout_margins(layoutgrids, fig, renderer, h_pad=h_pad,
117 w_pad=w_pad, hspace=hspace, wspace=wspace)
118 make_margin_suptitles(layoutgrids, fig, renderer, h_pad=h_pad,
119 w_pad=w_pad)
120

Callers 1

executeMethod · 0.90

Calls 15

make_layoutgridsFunction · 0.85
make_layout_marginsFunction · 0.85
make_margin_suptitlesFunction · 0.85
match_submerged_marginsFunction · 0.85
check_no_collapsed_axesFunction · 0.85
reposition_axesFunction · 0.85
compress_fixed_aspectFunction · 0.85
reset_marginsFunction · 0.85
update_variablesMethod · 0.80
get_in_layoutMethod · 0.80
get_inner_bboxMethod · 0.80
set_verticalalignmentMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…