code: def densitybin(
      x,
      weight: FloatArrayLike | None,
      binwidth: float | None,
      bins: int = 30,
      rangee: Optional[tuple[float, float]] = None,
  ):
      """
      Do density binning
  
      It does not collapse each bin with a count.
  
      Parameters
      ----------
      x : array_like
          Numbers to bin
      weight : array_like
          Weights
      binwidth : numeric
          Size of the bins
      bins : int
          Number of bins
      rangee : tuple
          Range of x
  
      Returns
      -------
      data : DataFrame
      """
      if all(pd.isna(x)):
          return pd.DataFrame()
  
      if weight is None:
          weight = np.ones(len(x))
      weight = np.asarray(weight)
      weight[np.isnan(weight)] = 0
  
      if rangee is None:
          rangee = np.min(x), np.max(x)
      if bins is None:
          bins = 30
      if binwidth is None:
          binwidth = np.ptp(rangee) / bins
  
      # Sort weight and x, by x
      order = np.argsort(x)
      weight = weight[order]
      x = x[order]
  
      cbin = 0  # Current bin ID
      bin_ids = []  # The bin ID for each observation
      # End position of current bin (scan left to right)
      binend = -np.inf
  
      # Scan list and put dots in bins
      for value in x:
          # If past end of bin, start a new bin at this point
          if value >= binend:
              binend = value + binwidth
              cbin = cbin + 1
          bin_ids.append(cbin)
  
      def func(series):
          return (series.min() + series.max()) / 2
  
      results = pd.DataFrame(
          {
              "x": x,
              "bin": bin_ids,
              "binwidth": binwidth,
              "weight": weight,
          }
      )
      # This is a plyr::ddply
      results["bincenter"] = results.groupby("bin")["x"].transform(func)
      return results
  
file_path: plotnine/plotnine/stats/stat_bindot.py
imports: from __future__ import annotations
  import typing
  from warnings import warn
  import numpy
  import pandas
  from .._utils import groupby_apply
  from ..doctools import document
  from ..exceptions import PlotnineError, PlotnineWarning
  from ..mapping.evaluation import after_stat
  from .binning import assign_bins, breaks_from_bins, breaks_from_binwidth, freedman_diaconis_bins
  from .stat import stat
label_desc: Use image node_id 1 for calling a global function with example usage: densitybin(x, weight, binwidth, bins, rangee) and returns: results, pd, unknown