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
Passing an incorrectly sized colour list to scatter should raise a relevant error #9209
If the length of the c argument to matplotlib.pyplot.scatter doesn't match the size of the x and y arguments, a confusing error message is raised: Invalid RGBA argument. Contrast this with the error that results if x and y are not the same size: x and y must be the same size. The error message for an incorrect size c array should be made more clear.
/usr/local/lib/python3.6/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
192 # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
193 # Test dimensionality to reject single floats.
--> 194 raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
195 # Return a tuple to prevent the cached value from being modified.
196 c = tuple(c.astype(float))
ValueError: Invalid RGBA argument: 0.58430716187559439
I am getting this error ValueError: c of shape (3854,) not acceptable as a color sequence for x with size 3854, y with size 3854 in version 2.2.4 of matplotlib. The error definitely isn't helpful in this case.
Reacted by Max Taggart, Deepak Walia, CDNoyes, LorenzoInvernizzi92, Arunothia Marappan, Sean O'Sullivan, spineight, Allison Youngblood, Amira Abbas, Prashant Saikia and 6 more
@sabyagunnersya I try both (n,1) and (n,). Both of them are not working! Is there any other solution? Thanks!
ValueError: c of shape (303262, 1) not acceptable as a color sequence for x with size 303262, y with size 303262
ValueError: c of shape (303262,) not acceptable as a color sequence for x with size 303262, y with size 303262
@soerendip What version of Matplotlib? I think we have improved that error message recently.
Do you have a minimal example that will produce that error?
I got the same error: ValueError: 'c' argument has 59 elements, which is not acceptable for use with 'x' with size 59, 'y' with size 59.
My version of Matplotlib is 3.1.3
Full error:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4284, in _parse_scatter_color_args
colors = mcolors.to_rgba_array(c)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py", line 294, in to_rgba_array
result[i] = to_rgba(cc, alpha)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py", line 177, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py", line 240, in _to_rgba_no_colorcycle
raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Python Files/multiclass.py", line 54, in <module>
c=y_fruits_2d, cmap=cmap_fruits, edgecolor = 'black', alpha=.7)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2848, in scatter
None else {}), **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1599, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4453, in scatter
get_next_color_func=self._get_patches_for_fill.get_next_color)
File "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4297, in _parse_scatter_color_args
.format(nc=n_elem, xs=xsize, ys=ysize)
ValueError: 'c' argument has 59 elements, which is not acceptable for use with 'x' with size 59, 'y' with size 59.
I've fixed it though -- changed Y to Y.values.reshape(Y.shape[0])
Activity
jklymak commentedon Sep 21, 2017
This is fixed in master. Should be fixed for 2.1 release. The error raised is
jklymak commentedon Sep 21, 2017
Closing - feel free to re-open if you think its not fixed in the upcoming 2.1. Thanks for the report!
jklymak commentedon Sep 21, 2017
Fixed in #7363
PorkShoulderHolder commentedon Feb 22, 2019
I am getting this error
ValueError: c of shape (3854,) not acceptable as a color sequence for x with size 3854, y with size 3854in version 2.2.4 of matplotlib. The error definitely isn't helpful in this case.sskgp commentedon Jun 18, 2019
@PorkShoulderHolder please change c to have a shape of (n,1) instead of (n,) - this works for me.
weihuaguo commentedon Oct 4, 2019
@sabyagunnersya I try both (n,1) and (n,). Both of them are not working! Is there any other solution? Thanks!
ValueError: c of shape (303262, 1) not acceptable as a color sequence for x with size 303262, y with size 303262
ValueError: c of shape (303262,) not acceptable as a color sequence for x with size 303262, y with size 303262
TTitcombe commentedon Nov 19, 2019
@PorkShoulderHolder @weihuaguo Is this the issue you were seeing? #15727
runnholm commentedon Nov 26, 2019
This works for me as well, but this does not seem like expected behaviour? There is no obvious reason (n,) should not work.
sorenwacker commentedon Jun 2, 2020
LoL, I just got this:
tacaswell commentedon Jun 2, 2020
@soerendip What version of Matplotlib? I think we have improved that error message recently.
Do you have a minimal example that will produce that error?
ngmaihuong commentedon Aug 10, 2020
I got the same error:
ValueError: 'c' argument has 59 elements, which is not acceptable for use with 'x' with size 59, 'y' with size 59.My version of Matplotlib is 3.1.3
Full error:
I've fixed it though -- changed Y to Y.values.reshape(Y.shape[0])