You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: matplotlib.colors.LinearSegmentedColormap.from_list doesn't work with hex representation of colors #27029
It worked last in 3.7.0. I think the problem is colors.to_rgba_array when c is a tuple, particularly line 438
if isinstance(c, tuple) and len(c) == 2:
if alpha is None:
c, alpha = c
In this case with my color list c = ('#E3DBCC', '#FF4B33') gets transformed into just the first value, and the second hex is treated like the alpha channel value. Thus eventually it reaches the if isinstance(c, str) bit and raises the error.
Indeed, if I add a third color, the problem disappears.
The original issue #26949 also used hexes but the failure path was the same regardless of whether I tried the hex representation or the abbreviated (“k”, “w”) colour representation. So I do not think we need an extra test to cover the hex version of this bug, but obviously I’m biased as it was my PR 🙂
Activity
jklymak commentedon Oct 8, 2023
Do you know what version this used to work with?
jose-vines-toteat commentedon Oct 8, 2023
It worked last in 3.7.0. I think the problem is colors.to_rgba_array when
cis a tuple, particularly line 438In this case with my color list
c = ('#E3DBCC', '#FF4B33')gets transformed into just the first value, and the second hex is treated like the alpha channel value. Thus eventually it reaches theif isinstance(c, str)bit and raises the error.Indeed, if I add a third color, the problem disappears.
jklymak commentedon Oct 8, 2023
This was fixed in #26952. However, I'm not sure #26952 has a test of hex, so maybe there should be another test added.
rcomer commentedon Oct 8, 2023
The original issue #26949 also used hexes but the failure path was the same regardless of whether I tried the hex representation or the abbreviated (“k”, “w”) colour representation. So I do not think we need an extra test to cover the hex version of this bug, but obviously I’m biased as it was my PR 🙂
jklymak commentedon Oct 8, 2023
Thanks for the report. This will be fixed in the next bug release.