Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 855fe67

Browse files
committed
Use check_getitem in legend location resolution.
... and remove a trailing dot in an exception message (consistently with most of such messages).
1 parent b6a6414 commit 855fe67

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/matplotlib/legend.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,11 @@ def __init__(self, parent, handles, labels,
460460
if not self.isaxes and loc in [0, 'best']:
461461
loc = 'upper right'
462462
if isinstance(loc, str):
463-
if loc not in self.codes:
464-
raise ValueError(
465-
"Unrecognized location {!r}. Valid locations are\n\t{}\n"
466-
.format(loc, '\n\t'.join(self.codes)))
467-
else:
468-
loc = self.codes[loc]
463+
loc = _api.check_getitem(self.codes, loc=loc)
469464
if not self.isaxes and loc == 0:
470465
raise ValueError(
471466
"Automatic legend placement (loc='best') not implemented for "
472-
"figure legend.")
467+
"figure legend")
473468

474469
self._mode = mode
475470
self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)

0 commit comments

Comments
 (0)