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

Function _get_packed_offsets

lib/matplotlib/offsetbox.py:70–148  ·  view source on GitHub ↗

r""" Pack boxes specified by their *widths*. For simplicity of the description, the terminology used here assumes a horizontal layout, but the function works equally for a vertical layout. There are three packing *mode*\s: - 'fixed': The elements are packed tight to the left w

(widths, total, sep, mode="fixed")

Source from the content-addressed store, hash-verified

68
69
70def _get_packed_offsets(widths, total, sep, mode="fixed"):
71 r"""
72 Pack boxes specified by their *widths*.
73
74 For simplicity of the description, the terminology used here assumes a
75 horizontal layout, but the function works equally for a vertical layout.
76
77 There are three packing *mode*\s:
78
79 - 'fixed': The elements are packed tight to the left with a spacing of
80 *sep* in between. If *total* is *None* the returned total will be the
81 right edge of the last box. A non-*None* total will be passed unchecked
82 to the output. In particular this means that right edge of the last
83 box may be further to the right than the returned total.
84
85 - 'expand': Distribute the boxes with equal spacing so that the left edge
86 of the first box is at 0, and the right edge of the last box is at
87 *total*. The parameter *sep* is ignored in this mode. A total of *None*
88 is accepted and considered equal to 1. The total is returned unchanged
89 (except for the conversion *None* to 1). If the total is smaller than
90 the sum of the widths, the laid out boxes will overlap.
91
92 - 'equal': If *total* is given, the total space is divided in N equal
93 ranges and each box is left-aligned within its subspace.
94 Otherwise (*total* is *None*), *sep* must be provided and each box is
95 left-aligned in its subspace of width ``(max(widths) + sep)``. The
96 total width is then calculated to be ``N * (max(widths) + sep)``.
97
98 Parameters
99 ----------
100 widths : list of float
101 Widths of boxes to be packed.
102 total : float or None
103 Intended total length. *None* if not used.
104 sep : float or None
105 Spacing between boxes.
106 mode : {'fixed', 'expand', 'equal'}
107 The packing mode.
108
109 Returns
110 -------
111 total : float
112 The total width needed to accommodate the laid out boxes.
113 offsets : array of float
114 The left offsets of the boxes.
115 """
116 _api.check_in_list(["fixed", "expand", "equal"], mode=mode)
117
118 if mode == "fixed":
119 offsets_ = np.cumsum([0] + [w + sep for w in widths])
120 offsets = offsets_[:-1]
121 if total is None:
122 total = offsets_[-1] - sep
123 return total, offsets
124
125 elif mode == "expand":
126 # This is a bit of a hack to avoid a TypeError when *total*
127 # is None and used in conjugation with tight layout.

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…