docstr: Add artists that reflect semantic mappings and put then in a legend.
docstr_tok: ["Add","artists","that","reflect","semantic","mappings","and","put","then","in","a","legend","."]
code: def _add_legend(
      self,
      ax_obj,
      artist,
      fill,
      element,
      multiple,
      alpha,
      artist_kws,
      legend_kws,
  ):
      """Add artists that reflect semantic mappings and put then in a legend."""
      # TODO note that this doesn't handle numeric mappings like the relational plots
      handles = []
      labels = []
      for level in self._hue_map.levels:
          color = self._hue_map(level)
  
          kws = self._artist_kws(
              artist_kws, fill, element, multiple, color, alpha
          )
  
          # color gets added to the kws to workaround an issue with barplot's color
          # cycle integration but it causes problems in this context where we are
          # setting artist properties directly, so pop it off here
          if "facecolor" in kws:
              kws.pop("color", None)
  
          handles.append(artist(**kws))
          labels.append(level)
  
      if isinstance(ax_obj, mpl.axes.Axes):
          ax_obj.legend(
              handles, labels, title=self.variables["hue"], **legend_kws
          )
      else:  # i.e. a FacetGrid. TODO make this better
          legend_data = dict(zip(labels, handles))
          ax_obj.add_legend(
              legend_data,
              title=self.variables["hue"],
              label_order=self.var_levels["hue"],
              **legend_kws,
          )
  
imports: from numbers import Number
  from functools import partial
  import math
  import textwrap
  import warnings
  import numpy
  import pandas
  import matplotlib
  import matplotlib.pyplot
  import matplotlib.transforms
  from matplotlib.cbook import normalize_kwargs
  from matplotlib.colors import to_rgba
  from matplotlib.collections import LineCollection
  from ._base import VectorPlotter
  from ._statistics import ECDF, Histogram, KDE
  from ._stats.counting import Hist
  from .axisgrid import FacetGrid, _facet_docs
  from .utils import remove_na, _get_transform_functions, _kde_support, _check_argument, _assign_default_kwargs, _default_color
  from .palettes import color_palette
  from .external import husl
  from .external.kde import gaussian_kde
  from ._docstrings import DocstringComponents, _core_docs
label_desc: Use image node_id 5 for calling the _DistributionPlotter obj's underlying member method code with example usage: obj._add_legend(ax_obj, artist, fill, element, multiple, alpha, artist_kws, legend_kws) without return types