# scatter takes (r,g,b) values between (0,1)
colors = np.array([[24,88,174],[255,0,0],[0,255,0]])/255
# lines
plt.plot([0,10,20], [0,10,20],'--')
# scatter has `c` option for colors
plt.scatter([0,10,20], [0, 10,20], c=colors)
输出:
0 投票
使用此代码,无论x和y是什么,点都将以这种模式着色:红色,绿色,蓝色:
import matplotlib.pyplot as plt
x = [0,10,20,30,35,60]
y = [0,5,40,35,15,40]
c = 'or--'
while len(x) > 0:
plt.plot(x,y,c)
if c == 'or--': c = 'og--'
elif c == 'og--': c = 'ob--'
else: c = 'or--'
x.pop(0)
y.pop(0)
plt.show ()