docs: def _paint_carto_legend(ax, values, legend_values, legend_labels, scale_func, legend_kwargs):
      """
      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.
      values : list
          A list of values 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.
      legend_values : list, optional
          If a legend is specified, equal intervals will be used for the "points" in the legend by default. However,
          particularly if your scale is non-linear, oftentimes this isn't what you want. If this variable is provided as
          well, the values included in the input will be used by the legend instead.
      legend_labels : list, optional
          If a legend is specified, this parameter can be used to control what names will be attached to
      scale_func : ufunc
          The scaling function being used.
      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.
  
      Returns
      -------
      None.
      """
  
      # Set up the legend values.
      if legend_values is not None:
          display_values = legend_values
      else:
          display_values = np.linspace(np.max(values), np.min(values), num=5)
      display_labels = legend_labels if (legend_labels is not None) else display_values
  
      # Paint patches.
      patches = []
      for value in display_values:
          patches.append(mpl.lines.Line2D([0], [0], linestyle='None',
                         marker="o",
                         markersize=(20*scale_func(value))**(1/2),
                         markerfacecolor='None'))
      if legend_kwargs is None: legend_kwargs = dict()
      ax.legend(patches, display_labels, numpoints=1, fancybox=True, **legend_kwargs)