def _set_lim(data=[], dmin=None, dmax=None, bins=2):
    """It sets the limits of the plot of a list of data depending on the number of bins of the plot and whatever or not the limits are explicitly provided. It is used by the 'set_xlim' and 'set_ylim' functions."""
    bins_offset = 0
    if dmin == None:
        bins_offset += 0.5
        if data == []:
            d_min = 0
        else:
            d_min = min(data)
    else:
        d_min = dmin
    if dmax == None:
        bins_offset += 0.5
        if data == []:
            d_max = 0
        else:
            d_max = max(data)
    else:
        d_max = dmax
    if bins == 1:
        bins_offset = 0.5
    if d_min == d_max:
        span = 0.1 * d_min
    else:
        span = (d_max - d_min) / (bins - bins_offset)
    minimum = d_min
    if dmin == None:
        minimum -= 0.5 * span
    maximum = d_max
    if dmax == None:
        maximum += 0.5 * span
    return minimum, maximum
