"""Utilities for visualization."""from__future__importannotationsimportcolorsysimportnumpyasnp
[docs]defgenerate_color_map(length:int)->list[tuple[int,int,int]]:"""Generate a color palette of [length] colors. Args: length (int): Number of colors to generate. Returns: list[tuple[int, int, int]]: List with different colors ranging from [0,255]. """brightness=0.7hsv=[(i/length,1,brightness)foriinrange(length)]colors_float=[colorsys.hsv_to_rgb(*c)forcinhsv]colors:list[int]=((np.array(colors_float)*255).astype(np.uint8).tolist())s=np.random.get_state()np.random.seed(0)result=[tuple(colors[i])foriinnp.random.permutation(len(colors))]np.random.set_state(s)returnresult