Often you pass a colormap to a plotting function, but you can also pass a number or array to a colormap and get the colors in return.
So to color each line according to a variable, do something like this:
numlines = 20
for i in np.linspace(0,1, numlines):
plt.plot(np.arange(numlines),np.tile([i],numlines), linewidth=4, color=plt.cm.RdYlBu(i))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…