class_docstr: Mapping that sets artist colors according to data values.
class_docstr_tok: ["Mapping","that","sets","artist","colors","according","to","data","values","."]
docstr: Determine colors when the hue mapping is categorical.
docstr_tok: ["Determine","colors","when","the","hue","mapping","is","categorical","."]
code: def categorical_mapping(self, data, palette, order):
      """Determine colors when the hue mapping is categorical."""
      # -- Identify the order and name of the levels
  
      levels = categorical_order(data, order)
      n_colors = len(levels)
  
      # -- Identify the set of colors to use
  
      if isinstance(palette, dict):
          missing = set(levels) - set(palette)
          if any(missing):
              err = "The palette dictionary is missing keys: {}"
              raise ValueError(err.format(missing))
  
          lookup_table = palette
  
      else:
          if palette is None:
              if n_colors <= len(get_color_cycle()):
                  colors = color_palette(None, n_colors)
              else:
                  colors = color_palette("husl", n_colors)
          elif isinstance(palette, list):
              colors = self._check_list_length(
                  levels, palette, "palette"
              )
          else:
              colors = color_palette(palette, n_colors)
  
          lookup_table = dict(zip(levels, colors))
  
      return levels, lookup_table
  
imports: from __future__ import annotations
  import warnings
  import itertools
  from copy import copy
  from collections import UserString
  from collections.abc import Iterable, Sequence, Mapping
  from numbers import Number
  from datetime import datetime
  import numpy
  import pandas
  import matplotlib
  from seaborn._core.data import PlotData
  from seaborn.palettes import QUAL_PALETTES, color_palette
  from seaborn.utils import _check_argument, _version_predates, desaturate, locator_to_legend_entries, get_color_cycle, remove_na
label_desc: Use image node_id 4 for calling the HueMapping obj's underlying member method code with example usage: obj.categorical_mapping(data, palette, order) and returns: levels,  lookup_table