ValueError: Invalid RGBA argument: 's'.'c' argument must either be valid as mpl color(s) or as numbe

本文记录了在使用matplotlib scatter模块时遇到的颜色赋值错误,详细解析了错误原因,并分享了将错误颜色名'mstyrose'更正为'mistyrose'的解决过程。

最近在使用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, 大意了, 蠢哭

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值