最近在使用matplotlib中的scatter模块时使用颜色赋值报错,报错代码如下
Traceback (most recent call last):
File "D:\Python3.7.2\lib\site-packages\matplotlib\colors.py", line 174, in to_rgba
rgba = _colors_full_map.cache[c, alpha]
KeyError: ('s', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python3.7.2\lib\site-packages\matplotlib\axes\_axes.py", line 4232, in scatter
colors = mcolors.to_rgba_array(c)
File "D:\Python3.7.2\lib\site-packages\matplotlib\colors.py", line 275, in to_rgba_array
result[i] = to_rgba(cc, alpha)
File "D:\Python3.7.2\lib\site-packages\matplotlib\colors.py", line 176, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "D:\Python3.7.2\lib\site-packages\matplotlib\colors.py", line 220, in _to_rgba_no_colorcycle
raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 's'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/12819/Desktop/CTA1/vessel/data/read_data.py", line 83, in <module>
color_list, vessel_num, vessel_slice_data)
File "C:\Users\12819\Desktop\CTA1\vessel\data\vessel2color.py", line 38, in pltsave_all_vessel
np.where(vessel_slice_data == cls)[1], c=color, s=1)
File "D:\Python3.7.2\lib\site-packages\matplotlib\pyplot.py", line 2864, in scatter
is not None else {}), **kwargs)
File "D:\Python3.7.2\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "D:\Python3.7.2\lib\site-packages\matplotlib\axes\_axes.py", line 4253, in scatter
.format(c)
ValueError: 'c' argument must either be valid as mpl color(s) or as numbers to be mapped to colors. Here c = mstyrose.
注意最后一行报错,显示调用c = mstyrose错误,我试着把mstyrose颜色换成其他的就好了,最后仔细查资料发现是mistyrose, 大意了, 蠢哭
本文记录了在使用matplotlib scatter模块时遇到的颜色赋值错误,详细解析了错误原因,并分享了将错误颜色名'mstyrose'更正为'mistyrose'的解决过程。
4385

被折叠的 条评论
为什么被折叠?



