我正在使用这个调色板;这是最终图形的样子:如何根据背景颜色调整前景色?我的第一个直觉是交换颜色。例如,如果它是最后一种颜色,则将其与最小颜色交换。但这模糊了中间的那些。p = myset.index(p0[i])print(str(set_length )+'-'+ str(p))print(set_length - p-1)c = colors[set_length - p-1]cv2.putText(img, TEXT, text_origin, TEXT_FACE, TEXT_SCALE, (c[2],c[1],c[0]))我采用按升序排列的列表中的数字索引。然后根据该索引获得颜色。列表的长度从此颜色中减去。
1 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
# First, store your palette:
pal = sns.color_palette("Or_Rd", 10)
# this function creates a contrasting color for given (r, g, b)
def contrast(x):
return tuple( 0 if c > 0.5 else 1 for c in x )
# so to create a list of colors contrasting with your palette:
contrasting_colors = [ contrast(c) for c in pal ]
添加回答
举报
0/150
提交
取消
