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

Method set_bbox_to_anchor

lib/matplotlib/legend.py:1117–1158  ·  view source on GitHub ↗

Set the bbox that the legend will be anchored to. Parameters ---------- bbox : `~matplotlib.transforms.BboxBase` or tuple The bounding box can be specified in the following ways: - A `.BboxBase` instance - A tuple of ``(left, bot

(self, bbox, transform=None)

Source from the content-addressed store, hash-verified

1115 return self._bbox_to_anchor
1116
1117 def set_bbox_to_anchor(self, bbox, transform=None):
1118 """
1119 Set the bbox that the legend will be anchored to.
1120
1121 Parameters
1122 ----------
1123 bbox : `~matplotlib.transforms.BboxBase` or tuple
1124 The bounding box can be specified in the following ways:
1125
1126 - A `.BboxBase` instance
1127 - A tuple of ``(left, bottom, width, height)`` in the given
1128 transform (normalized axes coordinate if None)
1129 - A tuple of ``(left, bottom)`` where the width and height will be
1130 assumed to be zero.
1131 - *None*, to remove the bbox anchoring, and use the parent bbox.
1132
1133 transform : `~matplotlib.transforms.Transform`, optional
1134 A transform to apply to the bounding box. If not specified, this
1135 will use a transform to the bounding box of the parent.
1136 """
1137 if bbox is None:
1138 self._bbox_to_anchor = None
1139 return
1140 elif isinstance(bbox, BboxBase):
1141 self._bbox_to_anchor = bbox
1142 else:
1143 try:
1144 l = len(bbox)
1145 except TypeError as err:
1146 raise ValueError(f"Invalid bbox: {bbox}") from err
1147
1148 if l == 2:
1149 bbox = [bbox[0], bbox[1], 0, 0]
1150
1151 self._bbox_to_anchor = Bbox.from_bounds(*bbox)
1152
1153 if transform is None:
1154 transform = BboxTransformTo(self.parent.bbox)
1155
1156 self._bbox_to_anchor = TransformedBbox(self._bbox_to_anchor,
1157 transform)
1158 self.stale = True
1159
1160 def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer):
1161 """

Callers 3

__init__Method · 0.95
_update_locMethod · 0.45

Calls 3

BboxTransformToClass · 0.90
TransformedBboxClass · 0.90
from_boundsMethod · 0.80

Tested by

no test coverage detected