CS3 = plt.contourf(Z, levels, cmap=mymap)
plt.clf()
X = [[1, 2], [1, 2], [1, 2], [1, 2]]
Y = [[1, 2], [1, 3], [1, 4], [1, 5]]
Z = [-40, -20, 0, 30]
for x, y, z in zip(X, Y, Z):
    r = (float(z) - min) / (max - min)
g = 0
b = 1 - r
plt.plot(x, y, color=(r, g, b))
plt.colorbar(CS3)
plt.show()
Matplotlib - add colorbar to a sequence of line plots