diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index a073f832ba98..96d4a6c16890 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -460,16 +460,11 @@ def __init__(self, parent, handles, labels, if not self.isaxes and loc in [0, 'best']: loc = 'upper right' if isinstance(loc, str): - if loc not in self.codes: - raise ValueError( - "Unrecognized location {!r}. Valid locations are\n\t{}\n" - .format(loc, '\n\t'.join(self.codes))) - else: - loc = self.codes[loc] + loc = _api.check_getitem(self.codes, loc=loc) if not self.isaxes and loc == 0: raise ValueError( "Automatic legend placement (loc='best') not implemented for " - "figure legend.") + "figure legend") self._mode = mode self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)