Description
Bug summary
Incrementing from v3.7 to v3.8 the option to specify a start and end value is no longer functioning when two values are specified. It still works when three are specified.
## This works:
matplotlib.colors.LinearSegmentedColormap.from_list("myMap", ["#000000", "#FFFFFF"])
## This does not:
matplotlib.colors.LinearSegmentedColormap.from_list("myMap", [(0,"#000000"), (1,"#FFFFFF")])
Code for reproduction
matplotlib.colors.LinearSegmentedColormap.from_list("myMap", [(0,"#000000"), (1,"#FFFFFF")])
Actual outcome
Traceback (most recent call last):
File "", line 1, in
File "/Users/dave/.local/share/virtualenvs/projects-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 1065, in from_list
colors : array-like of colors or array-like of (value, color)
File "/Users/dave/.local/share/virtualenvs/projects-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 489, in to_rgba_array
pass
ValueError: '#000000' is not a valid color value.
Expected outcome
<matplotlib.colors.LinearSegmentedColormap object at 0x101e7f520>
Additional information
Worked in 3.7
The issue I think is related to zipped values being passed to r, g, b, a = to_rgba_array(colors).T
. A tuple gets passed in rather than a list.
## tuple len 2 fails
>>> matplotlib.colors.to_rgba_array(("#000000", "#FFFFFF"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dave/.local/share/virtualenvs/model_train-t0xU6-ce/lib/python3.10/site-packages/matplotlib/colors.py", line 489, in to_rgba_array
pass
ValueError: '#000000' is not a valid color value.
## list works
>>> matplotlib.colors.to_rgba_array(["#000000", "#FFFFFF"])
array([[0., 0., 0., 1.],
[1., 1., 1., 1.]])
Changing r, g, b, a = to_rgba_array(colors).T
in colors.py:LinearSegmentedColormap.from_list
to r, g, b, a = to_rgba_array(list(colors)).T
or similar may fix.
Operating system
OS/X
Matplotlib Version
3.8.0
Matplotlib Backend
MacOSX
Python version
Python 3.10.9
Jupyter version
No response
Installation
None