Closed
Description
Bug report
Bug summary
matplotlib.colors.is_color_like
returns True
on strings containing integers, even though these are invalid colours when passed to plt.scatter
or equivalent.
Code for reproduction
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
c = np.arange(1000).astype(str)
X = np.random.normal(0, 1, [1000, 2])
assert all([matplotlib.colors.is_color_like(color) for color in c])
plt.scatter(X[:, 0], X[:, 1], c=c)
Actual outcome
>>> import matplotlib
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>>
>>> c = np.arange(1000).astype(str)
>>> X = np.random.normal(0, 1, [1000, 2])
>>>
>>> assert all([matplotlib.colors.is_color_like(color) for color in c])
>>> plt.scatter(X[:, 0], X[:, 1], c=c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2864, in scatter
is not None else {}), **kwargs)
File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "/usr/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4297, in scatter
alpha=alpha
File "/usr/lib/python3.7/site-packages/matplotlib/collections.py", line 899, in __init__
Collection.__init__(self, **kwargs)
File "/usr/lib/python3.7/site-packages/matplotlib/collections.py", line 131, in __init__
self.set_facecolor(facecolors)
File "/usr/lib/python3.7/site-packages/matplotlib/collections.py", line 685, in set_facecolor
self._set_facecolor(c)
File "/usr/lib/python3.7/site-packages/matplotlib/collections.py", line 668, in _set_facecolor
self._facecolors = mcolors.to_rgba_array(c, self._alpha)
File "/usr/lib/python3.7/site-packages/matplotlib/colors.py", line 260, in to_rgba_array
raise ValueError("RGBA values should be within 0-1 range")
ValueError: RGBA values should be within 0-1 range
Expected outcome
I would expect either the scatter
call to successfully recognise these as colours, or the is_color_like
calls to return False
. The latter is what I would expect of these two.
Matplotlib version
- Operating system: Arch Linux
- Matplotlib version: 3.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: Python 3.7.1
- Jupyter version (if applicable): N/A
- Other libraries:
numpy
1.15.0
matplotlib
installed from pip
. The example code runs without any errors on Windows, Python 3.6, matplotlib
2.2.2.
Metadata
Metadata
Assignees
Labels
No labels