您正在使用该列表中的项目索引timeDiffInt列表,如果这些是大于列表长度的整数,则会显示此错误.
你想要你的散射包含两种颜色吗?值为0的一种颜色和其他值的另一种颜色?
您可以使用Numpy将列表更改为0和1:
timeDiffInt = np.where(np.array(timeDiffInt) == 0, 0, 1)
然后,Scatter将为这两个值使用不同的颜色.
fig, ax = plt.subplots(figsize=(5,5))
ax.scatter(x,y,c=timeDiffInt, s=150, marker='<', edgecolor='none')
编辑:
您可以通过自己制作色彩图来为特定值创建颜色:
fig, ax = plt.subplots(figsize=(5,5))
colors = ['red', 'blue']
levels = [0, 1]
cmap, norm = mpl.colors.from_levels_and_colors(levels=levels, colors=colors, extend='max')
ax.scatter(x,y,c=timeDiffInt, s=150, marker='<', edgecolor='none', cmap=cmap, norm=norm)