@@ -485,9 +485,12 @@ def __init__(self, parent, handles, labels,
485485 self .parent = parent
486486
487487 if loc is None :
488+ self ._loc_used_default = True
488489 loc = rcParams ["legend.loc" ]
489490 if not self .isaxes and loc in [0 , 'best' ]:
490491 loc = 'upper right'
492+ else :
493+ self ._loc_used_default = False
491494 if isinstance (loc , str ):
492495 if loc not in self .codes :
493496 if self .isaxes :
@@ -568,7 +571,8 @@ def __init__(self, parent, handles, labels,
568571 else :
569572 self .get_frame ().set_alpha (framealpha )
570573
571- self ._loc = loc
574+ self ._set_loc (loc , is_initial_setting = True )
575+
572576 # figure out title fontsize:
573577 if title_fontsize is None :
574578 title_fontsize = rcParams ['legend.title_fontsize' ]
@@ -588,10 +592,13 @@ def _set_artist_props(self, a):
588592
589593 a .set_transform (self .get_transform ())
590594
591- def _set_loc (self , loc ):
595+ def _set_loc (self , loc , is_initial_setting = False ):
592596 # find_offset function will be provided to _legend_box and
593597 # _legend_box will draw itself at the location of the return
594598 # value of the find_offset.
599+ if not is_initial_setting :
600+ # User manually changed self._loc
601+ self ._loc_used_default = False
595602 self ._loc_real = loc
596603 self .stale = True
597604 self ._legend_box .set_offset (self ._findoffset )
@@ -1108,7 +1115,8 @@ def _find_best_position(self, width, height, renderer, consider=None):
11081115 assert self .isaxes
11091116
11101117 verts , bboxes , lines , offsets = self ._auto_legend_data ()
1111- if len (verts ) + len (bboxes ) + len (lines ) + len (offsets ) > 500000 :
1118+ if self ._loc_used_default and verts .shape [0 ] > 200000 :
1119+ # this size results in a 3+ second render time on a good machine
11121120 warnings .warn (
11131121 'Creating legend with loc="best" can be slow with large'
11141122 ' amounts of data.'
0 commit comments