code: def val_to_bin_bounded(edges, x):
      
      nbins = len(edges) - 1
      ibin = val_to_bin(edges, x)
      ibin[ibin < 0] = 0
      ibin[ibin > nbins - 1] = nbins - 1
      return ibin
docs: Convert axis coordinate to bin index.