python不带颜色的图形_python – Matplotlib – 为某些数据点绘制不同颜色的图

您正在使用该列表中的项目索引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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值