If I understand correctly, the function:
matplotlib.pyplot.plot(x, y)
plots len(x)-1 separate line segments - one going from (x[0], y[0]) to (x
You should be able to use matplotlib.collections.LineCollection which accepts a colors
parameter (sequence of RGBA tuples).
If you implement a colorbar, something similar to this, then you should be able to do it in one line. The trick may be to pick a colorscale that changes on the order of your line segments.