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

Skip to content

Commit 020acb6

Browse files
committed
FIX: fix the positional arguments
1 parent 6cce6a5 commit 020acb6

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lib/matplotlib/figure.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,22 +1113,25 @@ def legend(self, *args, **kwargs):
11131113
# extra_args = extra_args[1:]
11141114
pass
11151115
transform = kwargs.pop('bbox_transform', self.transSubfigure)
1116-
loc = kwargs.pop('loc', None)
1117-
# handle outside legends:
1118-
outside = None
1119-
if isinstance(loc, str):
1120-
if loc.split()[0] == 'outside':
1121-
loc = loc.replace('outside ', '')
1122-
outside = loc.replace('center ', '')
1123-
outside = outside.split()[0]
1124-
locs = loc.split()
1125-
if len(locs) > 1 and locs[0] in ('right', 'left'):
1126-
# locs doesn't accept "left upper", etc, so swap
1127-
if locs[0] != 'center':
1128-
locs = locs[::-1]
1129-
loc = locs[0] + ' ' + locs[1]
1130-
1131-
kwargs['loc'] = loc
1116+
if 'loc' in kwargs:
1117+
# need to protect this in case loc was passed in
1118+
# positionally...
1119+
loc = kwargs.pop('loc', None)
1120+
# handle outside legends:
1121+
outside = None
1122+
if isinstance(loc, str):
1123+
if loc.split()[0] == 'outside':
1124+
loc = loc.replace('outside ', '')
1125+
outside = loc.replace('center ', '')
1126+
outside = outside.split()[0]
1127+
locs = loc.split()
1128+
if len(locs) > 1 and locs[0] in ('right', 'left'):
1129+
# locs doesn't accept "left upper", etc, so swap
1130+
if locs[0] != 'center':
1131+
locs = locs[::-1]
1132+
loc = locs[0] + ' ' + locs[1]
1133+
1134+
kwargs['loc'] = loc
11321135
# explicitly set the bbox transform if the user hasn't.
11331136
l = mlegend.Legend(self, handles, labels, *extra_args,
11341137
bbox_transform=transform, **kwargs)

0 commit comments

Comments
 (0)