Skip to content

Instantly share code, notes, and snippets.

@ven-kyoshiro
Last active May 22, 2019 04:58
Show Gist options
  • Save ven-kyoshiro/dc3f65463900b67121547e5c02d7f590 to your computer and use it in GitHub Desktop.
Save ven-kyoshiro/dc3f65463900b67121547e5c02d7f590 to your computer and use it in GitHub Desktop.
[0,1] to RGB tuple
import matplotlib.pyplot as plt
import numpy as np
def val2color(x):
assert x<=1, 'x should be in the [0,1]'
base =0.5
if x<1/3:
g=x*3.
r= 1-g
b=0
elif x>2/3:
r = (x-2/3)*3.
b = 1.-r
g=0
else:
b=(x-1/3)*3
g = 1-b
r=0
return (r*(1-base)+base,g*(1-base)+base,b*(1-base)+base)
%matplotlib inline
x = np.linspace(0,1,100)
plt.scatter(x,x,color=[val2color(xx) for xx in x])
@ven-kyoshiro
Copy link
Author

result

@ven-kyoshiro
Copy link
Author

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment