Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
Using a scatter plot with a single point at. But using a single number for the "c" keyword gave an slightly unhelpful error about aTypeError
frommcolors.to_rgba_array
. Acmap
is used to map the number given but this is omitted here as the Error is still reproduced.
Code for reproduction
importmaptlotlib.pyplotaspltplt.scatter([0], [1],c=0.5)
Actual outcome
---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-16-a8c544fd7de9> in <module>()----> 1 plt.scatter([0], [1], c=0.5)~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs) 3376 vmin=vmin, vmax=vmax, alpha=alpha, 3377 linewidths=linewidths, verts=verts,-> 3378 edgecolors=edgecolors, data=data, **kwargs) 3379 finally: 3380 ax._hold = washold~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs) 1715 warnings.warn(msg % (label_namer, func.__name__), 1716 RuntimeWarning, stacklevel=2)-> 1717 return func(ax, *args, **kwargs) 1718 pre_doc = inner.__doc__ 1719 if pre_doc is None:~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs) 3981 try: 3982 # must be acceptable as PathCollection facecolors-> 3983 colors = mcolors.to_rgba_array(c) 3984 except ValueError: 3985 # c not acceptable as PathCollection facecolor~/anaconda3/lib/python3.6/site-packages/matplotlib/colors.py in to_rgba_array(c, alpha) 229 pass 230 # Convert one at a time.--> 231 result = np.empty((len(c), 4), float) 232 for i, cc in enumerate(c): 233 result[i] = to_rgba(cc, alpha)TypeError: object of type 'int' has no len()
Expected outcome
Have a useful message from anexcept TypeError:
from the failingcolors = mcolors.to_rgba_array(c)
call in line 3983 much like theValueError
except, would probably do it.
Helpfully indicating thatc
must be the correct type (color, sequence, or sequence of color).
Note:
With x, y, and c all as single numbers the scatter plot call runs without any errors raised,
e.g.plt.scatter(0, 1, c=0.5)