def colour_wheel(samples=1024, clip_circle=True, method='Colour'):
xx, yy = np.meshgrid(
np.linspace(-1, 1, samples), np.linspace(-1, 1, samples))
S = np.sqrt(xx ** 2 + yy ** 2)
H = (np.arctan2(xx, yy) + np.pi) / (np.pi * 2)
HSV = colour.utilities.tstack([H, S, np.ones(H.shape)])
RGB = colour.HSV_to_RGB(HSV)
if clip_circle == True:
RGB[S > 1] = 0
A = np.where(S > 1, 0, 1)
else:
A = np.ones(S.shape)
if method.lower()== 'matplotlib':
RGB = colour.utilities.orient(RGB, '90 CW')
elif method.lower()== 'nuke':
RGB = colour.utilities.orient(RGB, 'Flip')
RGB = colour.utilities.orient(RGB, '90 CW')
R, G, B = colour.utilities.tsplit(RGB)
return colour.utilities.tstack([R, G, B, A])
我们在这个交互式的 Jupyter Notebook Matplotlib 小部件中使用它:
该代码库在此处可用:https://github.com/colour-science/gamut-mapping-ramblings
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
rho = np.linspace(0,1,100) # Radius of 1, distance from center to outer edge
phi = np.linspace(0, math.pi*2.,1000 ) # in radians, one full circle
RHO, PHI = np.meshgrid(rho,phi) # get every combination of rho and phi
h = (PHI-PHI.min()) / (PHI.max()-PHI.min()) # use angle to determine hue, normalized from 0-1
h = np.flip(h)
s = RHO # saturation is set as a function of radias
v = np.ones_like(RHO) # value is constant
# convert the np arrays to lists. This actually speeds up the colorsys call
h,s,v = h.flatten().tolist(), s.flatten().tolist(), v.flatten().tolist()
c = [colorsys.hsv_to_rgb(*x) for x in zip(h,s,v)]
c = np.array(c)
ax.scatter(PHI, RHO, c=c)
_ = ax.axis('off')
请注意,这会导致蓝/紫色的点向上,而红色的点向右。根据我的经验,这是典型的光流色调图。要实现 OP 发布的图像,请更改以下内容,以便图形从左侧开始绘制:phi = np.linspace(math.pi, math.pi*3.,1000 ) # in radians, one full circle