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

Function _auto_adjust_subplotpars

lib/matplotlib/_tight_layout.py:20–157  ·  view source on GitHub ↗

Return a dict of subplot parameters to adjust spacing between subplots or ``None`` if resulting Axes would have zero height or width. Note that this function ignores geometry information of subplot itself, but uses what is given by the *shape* and *subplot_list* parameters. Also,

(
        fig, renderer, shape, span_pairs, subplot_list,
        ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None)

Source from the content-addressed store, hash-verified

18
19
20def _auto_adjust_subplotpars(
21 fig, renderer, shape, span_pairs, subplot_list,
22 ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
23 """
24 Return a dict of subplot parameters to adjust spacing between subplots
25 or ``None`` if resulting Axes would have zero height or width.
26
27 Note that this function ignores geometry information of subplot itself, but
28 uses what is given by the *shape* and *subplot_list* parameters. Also, the
29 results could be incorrect if some subplots have ``adjustable=datalim``.
30
31 Parameters
32 ----------
33 shape : tuple[int, int]
34 Number of rows and columns of the grid.
35 span_pairs : list[tuple[slice, slice]]
36 List of rowspans and colspans occupied by each subplot.
37 subplot_list : list of subplots
38 List of subplots that will be used to calculate optimal subplot_params.
39 pad : float
40 Padding between the figure edge and the edges of subplots, as a
41 fraction of the font size.
42 h_pad, w_pad : float
43 Padding (height/width) between edges of adjacent subplots, as a
44 fraction of the font size. Defaults to *pad*.
45 rect : tuple
46 (left, bottom, right, top), default: None.
47 """
48 rows, cols = shape
49
50 font_size_inch = (FontProperties(
51 size=mpl.rcParams["font.size"]).get_size_in_points() / 72)
52 pad_inch = pad * font_size_inch
53 vpad_inch = h_pad * font_size_inch if h_pad is not None else pad_inch
54 hpad_inch = w_pad * font_size_inch if w_pad is not None else pad_inch
55
56 if len(span_pairs) != len(subplot_list) or len(subplot_list) == 0:
57 raise ValueError
58
59 if rect is None:
60 margin_left = margin_bottom = margin_right = margin_top = None
61 else:
62 margin_left, margin_bottom, _right, _top = rect
63 margin_right = 1 - _right if _right else None
64 margin_top = 1 - _top if _top else None
65
66 vspaces = np.zeros((rows + 1, cols))
67 hspaces = np.zeros((rows, cols + 1))
68
69 if ax_bbox_list is None:
70 ax_bbox_list = [
71 Bbox.union([ax.get_position(original=True) for ax in subplots])
72 for subplots in subplot_list]
73
74 for subplots, ax_bbox, (rowspan, colspan) in zip(
75 subplot_list, ax_bbox_list, span_pairs):
76 if all(not ax.get_visible() for ax in subplots):
77 continue

Callers 1

get_tight_layout_figureFunction · 0.85

Calls 10

FontPropertiesClass · 0.90
unionMethod · 0.80
transform_bboxMethod · 0.80
get_size_inchesMethod · 0.80
maxMethod · 0.80
get_in_layoutMethod · 0.80
get_positionMethod · 0.45
get_visibleMethod · 0.45
invertedMethod · 0.45
get_window_extentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…