Commit df68e809 authored by Connor Hainje's avatar Connor Hainje
Browse files

Fix linear colormap function to use HSL, not HSV

parent efcfd9ab
...@@ -50,12 +50,28 @@ def make_colormap(color_list, detectors=True): ...@@ -50,12 +50,28 @@ def make_colormap(color_list, detectors=True):
return cmap return cmap
def _hsv_to_hsl(color):
H = color[0]
L = color[2] * (1 - 0.5 * color[1])
S = 0 if (L == 0 or L == 1) else (color[2] - L) / min(L, 1 - L)
return (H, S, L)
def _hsl_to_hsv(color):
H = color[0]
V = color[2] + color[1] * min(color[2], 1 - color[2])
S = 0 if V == 0 else 2 * (1 - color[2] / V)
return (H, S, V)
def make_linear_colormap(color, cmap_name="custom_cmap", low=0.3, high=0.9): def make_linear_colormap(color, cmap_name="custom_cmap", low=0.3, high=0.9):
from matplotlib.colors import to_rgba, rgb_to_hsv, hsv_to_rgb from matplotlib.colors import to_rgba, rgb_to_hsv, hsv_to_rgb
hsv = rgb_to_hsv(to_rgba(color, alpha=1)[:3]) hsv = rgb_to_hsv(to_rgba(color, alpha=1)[:3])
lo = hsv_to_rgb((hsv[0], hsv[1], low)) hsl = _hsv_to_hsl(hsv)
hi = hsv_to_rgb((hsv[0], hsv[1], high))
lo = hsv_to_rgb(_hsl_to_hsv((hsl[0], hsl[1], low)))
hi = hsv_to_rgb(_hsl_to_hsv((hsl[0], hsl[1], high)))
cdict = { cdict = {
"red": ((0.0, lo[0], lo[0]), (1.0, hi[0], hi[0])), "red": ((0.0, lo[0], lo[0]), (1.0, hi[0], hi[0])),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment