def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer):
    assert loc in range(1, 11)
BEST, UL, UR, LL, LR, R, CL, CR, LC, UC, C = list(range(11))
anchor_coefs = {UR: 'NE', UL: 'NW', LL: 'SW', LR: 'SE', R: 'E', CL: 'W', CR:
    'E', LC: 'S', UC: 'N', C: 'C'}
c = anchor_coefs[loc]
fontsize = renderer.points_to_pixels(self._fontsize)
container = parentbbox.padded(-self.borderaxespad * fontsize)
anchored_box = bbox.anchored(c, container=container)
return anchored_box.x0, anchored_box.y0
Legend._get_anchored_bbox = _get_anchored_bbox
matplotlib legend location default