Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Connor Hainje
pidanalysis
Commits
df68e809
Commit
df68e809
authored
Mar 03, 2022
by
Connor Hainje
Browse files
Fix linear colormap function to use HSL, not HSV
parent
efcfd9ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
packages/pidplots/pidplots/colors.py
View file @
df68e809
...
...
@@ -50,12 +50,28 @@ def make_colormap(color_list, detectors=True):
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
):
from
matplotlib.colors
import
to_rgba
,
rgb_to_hsv
,
hsv_to_rgb
hsv
=
rgb_to_hsv
(
to_rgba
(
color
,
alpha
=
1
)[:
3
])
lo
=
hsv_to_rgb
((
hsv
[
0
],
hsv
[
1
],
low
))
hi
=
hsv_to_rgb
((
hsv
[
0
],
hsv
[
1
],
high
))
hsl
=
_hsv_to_hsl
(
hsv
)
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
=
{
"red"
:
((
0.0
,
lo
[
0
],
lo
[
0
]),
(
1.0
,
hi
[
0
],
hi
[
0
])),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment