-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: colors.LinearSegmentedColormap.from_list does not take two tuples in 3.8.0 #26949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report and the debugging notes @dave-shirley-faraday. This bisects to #24691. |
This seems to depend on whether In [10]: to_rgba_array(["#000000", "#FFFFFF"])
Out[10]:
array([[0., 0., 0., 1.],
[1., 1., 1., 1.]])
In [11]: to_rgba_array(("#000000", "#FFFFFF"))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[11], line 1
----> 1 to_rgba_array(("#000000", "#FFFFFF"))
File ~/git_stuff/matplotlib/lib/matplotlib/colors.py:489, in to_rgba_array(c, alpha)
487 raise e
488 if isinstance(c, str):
--> 489 raise ValueError(f"{c!r} is not a valid color value.")
491 if len(c) == 0:
492 return np.zeros((0, 4), float)
ValueError: '#000000' is not a valid color value. Edit: sorry, I see you already said that! |
Yes I think with the new parameterization of [edit] Yup, looks like your PR should address |
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.
Code for reproduction
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.Changing
r, g, b, a = to_rgba_array(colors).T
incolors.py:LinearSegmentedColormap.from_list
tor, 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
The text was updated successfully, but these errors were encountered: