Skip to content

Commit 352e49f

Browse files
committed
Support hex colors in colormap_from_single_color and fix rgb issue
1 parent e6411fa commit 352e49f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/simdec/visualization.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@
3434
]
3535

3636

37-
def colormap_from_single_color(rgba_color, *, factor=0.5):
37+
def colormap_from_single_color(
38+
rgba_color: list[float] | str, *, factor: float = 0.5
39+
) -> mpl.colors.LinearSegmentedColormap:
3840
"""Create a linear colormap using a single color."""
41+
if isinstance(rgba_color, str):
42+
rgba_color = mpl.colors.hex2color(rgba_color)
3943
# discard alpha channel
4044
if len(rgba_color) == 4:
4145
*rgb_color, alpha = rgba_color
4246
else:
43-
alpha = 1
47+
alpha = 1.0
4448
rgb_color = rgba_color
49+
rgba_color = list(rgba_color) + [1]
4550

4651
# lighten and darken from factor around single color
4752
hls_color = colorsys.rgb_to_hls(*rgb_color)

0 commit comments

Comments
 (0)