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
When using scatter, with the c= argument, I accidentally used an (n,2) array, instead of what I intended (an n-length vector). As expected, this did raise an error, however the error is misleading, and doesn't help much with debugging.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpx=np.linspace(0,1,10)
col=np.random.random(size=(10,2))
plt.scatter(x,x,c=col) # woops! should have been plt.scatter(x,x, c=col[:,0]).
Actual outcome
Traceback (most recent call last):
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/colors.py", line 158, in to_rgba
rgba = _colors_full_map.cache[c, alpha]
TypeError: unhashable type: 'numpy.ndarray'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4210, in scatter
colors = mcolors.to_rgba_array(c)
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/colors.py", line 259, in to_rgba_array
result[i] = to_rgba(cc, alpha)
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/colors.py", line 160, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/colors.py", line 215, in _to_rgba_no_colorcycle
raise ValueError("RGBA sequence should have length 3 or 4")
ValueError: RGBA sequence should have length 3 or 4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "instrumental_tests.py", line 218, in <module>
test_imaging_single_source()
File "instrumental_tests.py", line 156, in test_imaging_single_source
test_imaging(SingleSource())
File "instrumental_tests.py", line 91, in test_imaging
c=np.real(ctx.get("visibilities")))
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/__init__.py", line 1785, in inner
return func(ax, *args, **kwargs)
File "/home/steven/miniconda3/envs/py21cmmc_fg/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4223, in scatter
.format(nc=n_elem, xs=x.size, ys=y.size)
ValueError: 'c' argument has 10 elements, which is not acceptable for use with 'x' with size 10, 'y' with size 10.
Expected outcome
Expected exception would have been something like either ValueError: 'c' argument has 20 elements, which is not acceptable for use with 'x' with size 10, 'y' with size 10., or even better: ValueError: 'c' argument has shape (10,2), which is not acceptable for use with 'x' with size 10, 'y' with size 10.
Matplotlib version
v3.0.0
The text was updated successfully, but these errors were encountered:
Thanks for the report! I think the exact same issue is already opened at #12735 (the last part), feel free to comment on that thread if there's anything else we're missing (or request a reopen if I missed anything).
Bug report
Bug summary
When using
scatter
, with thec=
argument, I accidentally used an (n,2) array, instead of what I intended (ann
-length vector). As expected, this did raise an error, however the error is misleading, and doesn't help much with debugging.Code for reproduction
Actual outcome
Expected outcome
Expected exception would have been something like either
ValueError: 'c' argument has 20 elements, which is not acceptable for use with 'x' with size 10, 'y' with size 10.
, or even better:ValueError: 'c' argument has shape (10,2), which is not acceptable for use with 'x' with size 10, 'y' with size 10.
Matplotlib version
v3.0.0
The text was updated successfully, but these errors were encountered: