import colorsys


def ncolors(levels):
    """Generate len(levels) colors with darker-to-lighter variants
    for each color

    Args:
        levels(list): List with one element per required color. Element
            indicates number of variants for that color

    Returns:
        List of lists with variants for each rgb color hue

    """

    n = len(levels)

    def rgb2hex(rgb):
        return '#%02x%02x%02x' % rgb
    def hls2hex(h, l, s):
        return rgb2hex( tuple([int(x*255) for x in colorsys.hsv_to_rgb(h, l, s)]))

    colors = []

    for x in range(n):
        colors.append([])
        nlevels = levels[x]
        saturation_step = 1/(nlevels + 1)

        for l in range(nlevels):
            hsv_triple = (x*1.0/n, saturation_step*(l+1), 0.5)
        
            colors[x].append(hls2hex(*hsv_triple))
    
    return colors