【发布时间】:2021-07-21 11:52:01
【问题描述】:
我有一些带有一些数据的 python 对象,它们都有一个 id (1,2,3,4,5 ..... n)。我有一个 python 函数,我在其中发送这些对象之一,我想从中绘制数据,并根据 id 绘制不同的颜色。我尝试做一些我从其他问题中看到的事情,例如尝试将 id 整数转换为 RGB 值,如下所示:
Blue = integer & 255
Green = (integer >> 8) & 255
Red = (integer >> 16) & 255
return (RED/255, Green/255, Blue/255) # to get them into [0,1] interval
但问题在于,1、2、3 之类的接近数字之间的颜色将相同(基本上几乎具有相同的颜色)。有什么办法吗?
编辑:
所以我正在考虑做这样的事情:
def rgb_function(object_id):
random.seed(object_id)
value = random.uniform(0,1)
#then calculate RGB value based on this answer: https://stackoverflow.com/questions/55178857/convert-a-floating-point-number-to-rgb-vector
H = value;
R = abs(H * 6 - 3) - 1;
G = 2 - abs(H * 6 - 2);
B = 2 - abs(H * 6 - 4);
return max(0, min(1, R)), max(0, min(1, G)), max(0, min(1, B))
【问题讨论】:
-
n 有多大?
-
这取决于根据某些标准要创建多少个对象,我会说平均大约 600 个,但它有点动态
标签: python matplotlib rgb