Skip to content

Commit f89a78c

Browse files
committed
Some more refactoring courtesy of @timhoffm
1 parent 282ac53 commit f89a78c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/matplotlib/legend.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,11 @@ def __init__(self, parent, handles, labels,
484484
raise TypeError("Legend needs either Axes or Figure as parent")
485485
self.parent = parent
486486

487+
self._loc_used_default = loc is None
487488
if loc is None:
488-
self._loc_used_default = True
489489
loc = rcParams["legend.loc"]
490490
if not self.isaxes and loc in [0, 'best']:
491491
loc = 'upper right'
492-
else:
493-
self._loc_used_default = False
494492
if isinstance(loc, str):
495493
if loc not in self.codes:
496494
if self.isaxes:
@@ -571,7 +569,9 @@ def __init__(self, parent, handles, labels,
571569
else:
572570
self.get_frame().set_alpha(framealpha)
573571

574-
self._set_loc(loc, is_initial_setting=True)
572+
tmp = self._loc_used_default
573+
self._set_loc(loc)
574+
self._loc_used_default = tmp # ignore changes done by _set_loc
575575

576576
# figure out title fontsize:
577577
if title_fontsize is None:
@@ -592,13 +592,11 @@ def _set_artist_props(self, a):
592592

593593
a.set_transform(self.get_transform())
594594

595-
def _set_loc(self, loc, is_initial_setting=False):
595+
def _set_loc(self, loc):
596596
# find_offset function will be provided to _legend_box and
597597
# _legend_box will draw itself at the location of the return
598598
# value of the find_offset.
599-
if not is_initial_setting:
600-
# User manually changed self._loc
601-
self._loc_used_default = False
599+
self._loc_used_default = False
602600
self._loc_real = loc
603601
self.stale = True
604602
self._legend_box.set_offset(self._findoffset)

0 commit comments

Comments
 (0)