def colorbar_extension(colour_min, colour_max, data_min, data_max):
    """
    For the range specified by `colour_min' to `colour_max', return whether the data range specified by `data_min'
    and `data_max' is inside, outside or partially overlapping. This allows you to automatically set the `extend'
    keyword on a `matplotlib.pyplot.colorbar' call.

    Parameters
    ----------
    colour_min, colour_max : float
        Minimum and maximum value of the current colour bar limits.
    data_min, data_max : float
        Minimum and maximum value of the data limits.

    Returns
    -------
    extension : str
        Will be 'neither', 'both', 'min, or 'max' for the case when the colour_min and colour_max values are: equal
        to the data; inside the data range; only larger or only smaller, respectively.
    """

    if data_min < colour_min and data_max > colour_max:
        extension = 'both'
    elif data_min < colour_min and data_max <= colour_max:
        extension = 'min'
    elif data_min >= colour_min and data_max > colour_max:
        extension = 'max'
    else:
        extension = 'neither'

    return extension