docs: def _paint_hue_legend(ax, categories, cmap, legend_labels, legend_kwargs, figure=False):
      """
      Creates a legend and attaches it to the axis. Meant to be used when a ``legend=True`` parameter is passed.
  
      Parameters
      ----------
      ax : matplotlib.Axes instance
          The ``matplotlib.Axes`` instance on which a legend is being painted.
      categories : list
          A list of categories being plotted. May be either a list of int types or a list of unique entities in the
          data column (e.g. as generated via ``numpy.unique(data)``. This parameter is meant to be the same as that
          returned by the ``_discrete_colorize`` method.
      cmap : ``matplotlib.cm`` instance
          The `matplotlib` colormap instance which will be used to colorize the legend entries. This should be the
          same one used for colorizing the plot's geometries.
      legend_labels : list, optional
          If a legend is specified, this parameter can be used to control what names will be attached to the values.
      legend_kwargs : dict
          Keyword arguments which will be passed to the matplotlib legend instance on initialization. This parameter
          is provided to allow fine-tuning of legend placement at the top level of a plot method, as legends are very
          finicky.
      figure : boolean
          By default the legend is added to the axis requesting it. By specifying `figure=True` we may change the target
          to be the figure instead. This flag is used by the voronoi plot type, which occludes the base axis by adding a
          clip to it.
  
      Returns
      -------
      None
      """
  
      # Paint patches.
      patches = []
      for value, cat in enumerate(categories):
          patches.append(mpl.lines.Line2D([0], [0], linestyle="none",
                                marker="o",
                                markersize=10, markerfacecolor=cmap.to_rgba(value)))
      # I can't initialize legend_kwargs as an empty dict() by default because of Python's argument mutability quirks.
      # cf. http://docs.python-guide.org/en/latest/writing/gotchas/. Instead my default argument is None,
      # but that doesn't unpack correctly, necessitating setting and passing an empty dict here. Awkward...
      if not legend_kwargs: legend_kwargs = dict()
  
      # If we are given labels use those, if we are not just use the categories.
      target = ax.figure if figure else ax
  
      if legend_labels:
          target.legend(patches, legend_labels, numpoints=1, fancybox=True, **legend_kwargs)
      else:
          target.legend(patches, categories, numpoints=1, fancybox=True, **legend_kwargs)