def calc_centered_grid(cols_list, hpad=0.05, vpad=0.05):
    """Calculates a centered grid of Rectangles and their positions.

    Parameters
    ----------
    cols_list : [int]
        List of ints. Every entry represents a row with as many channels
        as the value.
    hpad : float, optional
        The amount of horizontal padding (default: 0.05).
    vpad : float, optional
        The amount of vertical padding (default: 0.05).

    Returns
    -------
    [[float, float, float, float]]
        A list of all rectangle positions in the form of [xi, xy, width,
        height] sorted from top left to bottom right.

    Examples
    --------
    Calculates a centered grid with 3 rows of 4, 3 and 2 columns

    >>> calc_centered_grid([4, 3, 2])

    Calculates a centered grid with more padding

    >>> calc_centered_grid([5, 4], hpad=.1, vpad=.75)
    """
    h = (1 - (len(cols_list) + 1) * vpad) / len(cols_list)
    w = (1 - (max(cols_list) + 1) * hpad) / max(cols_list)
    grid = []
    row = 1
    for l in cols_list:
        yi = 1 - (row * vpad + row * h)
        for i in range(l):
            m = 0.5 - (l * w + (l - 1) * hpad) / 2
            xi = m + i * hpad + i * w
            grid.append([xi, yi, w, h])
        row += 1
    return grid
