class_docstr: Place a legend on the figure/axes.
class_docstr_tok: ["Place","a","legend","on","the","figure\/axes","."]
docstr: Set the location of the legend.
  
  .. versionadded:: 3.8
  
  Parameters
  ----------
  %(_legend_kw_set_loc_doc)s
docstr_tok: ["Set","the","location","of","the","legend",".","..","versionadded",":",":","3.8","Parameters","--","--","--","--","--","%","(","_legend_kw_set_loc_doc",")","s"]
code: def set_loc(self, loc=None):
      """
      Set the location of the legend.
  
      .. versionadded:: 3.8
  
      Parameters
      ----------
      %(_legend_kw_set_loc_doc)s
      """
      loc0 = loc
      self._loc_used_default = loc is None
      if loc is None:
          loc = mpl.rcParams["legend.loc"]
          if not self.isaxes and loc in [0, "best"]:
              loc = "upper right"
  
      type_err_message = (
          "loc must be string, coordinate tuple, or"
          f" an integer 0-10, not {loc!r}"
      )
  
      # handle outside legends:
      self._outside_loc = None
      if isinstance(loc, str):
          if loc.split()[0] == "outside":
              # strip outside:
              loc = loc.split("outside ")[1]
              # strip "center" at the beginning
              self._outside_loc = loc.replace("center ", "")
              # strip first
              self._outside_loc = self._outside_loc.split()[0]
              locs = loc.split()
              if len(locs) > 1 and locs[0] in ("right", "left"):
                  # locs doesn't accept "left upper", etc, so swap
                  if locs[0] != "center":
                      locs = locs[::-1]
                  loc = locs[0] + " " + locs[1]
          # check that loc is in acceptable strings
          loc = _api.check_getitem(self.codes, loc=loc)
      elif np.iterable(loc):
          # coerce iterable into tuple
          loc = tuple(loc)
          # validate the tuple represents Real coordinates
          if len(loc) != 2 or not all(
              isinstance(e, numbers.Real) for e in loc
          ):
              raise ValueError(type_err_message)
      elif isinstance(loc, int):
          # validate the integer represents a string numeric value
          if loc < 0 or loc > 10:
              raise ValueError(type_err_message)
      else:
          # all other cases are invalid values of loc
          raise ValueError(type_err_message)
  
      if self.isaxes and self._outside_loc:
          raise ValueError(
              f"'outside' option for loc='{loc0}' keyword argument only "
              "works for figure legends"
          )
  
      if not self.isaxes and loc == 0:
          raise ValueError(
              "Automatic legend placement (loc='best') not implemented for "
              "figure legend"
          )
  
      tmp = self._loc_used_default
      self._set_loc(loc)
      self._loc_used_default = tmp
  
imports: import itertools
  import logging
  import numbers
  import time
  import numpy
  import matplotlib
  from matplotlib import _api, _docstring, cbook, colors, offsetbox
  from matplotlib.artist import Artist, allow_rasterization
  from matplotlib.cbook import silent_list
  from matplotlib.font_manager import FontProperties
  from matplotlib.lines import Line2D
  from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch, StepPatch
  from matplotlib.collections import Collection, CircleCollection, LineCollection, PathCollection, PolyCollection, RegularPolyCollection
  from matplotlib.text import Text
  from matplotlib.transforms import Bbox, BboxBase, TransformedBbox
  from matplotlib.transforms import BboxTransformTo, BboxTransformFrom
  from matplotlib.offsetbox import AnchoredOffsetbox, DraggableOffsetBox, HPacker, VPacker, DrawingArea, TextArea
  from matplotlib.container import ErrorbarContainer, BarContainer, StemContainer
  from .None import legend_handler
label_desc: Use image node_id 4 for calling the Legend obj's underlying member method code with example usage: obj.set_loc(loc) without return types