def _get_bin(x, low, high, num_bins):
    """Returns bin number for value `x`, in 1D histogram defined by `low`, `high`, `num_bins`.

    There are `num_bins` bins, spaced evenly between `low` and `high`.
    The right most edge is put into bin: num_bins - 1.
    BEWARE: will return value outside the range [0, num_bins-1] 
    if `x` is outside the inclusive range [low, high].
    
    Parameters
    ----------
    x : float
        A value to be placed into a bin.
    low : float
        The lower range of the bins. E.g. x_vals.min().
    high : float
        The upper range of the bins. E.g. x_vals.max().
    num_bins : int
        The number of bins.

    Returns
    -------
    bin_number : int
        The bin number for `x` 
        (value can be outside the range [0, n_bins-1]).

    """
    if x == high:
        return num_bins - 1
    else:
        return int(num_bins * (x - low) / (high - low))