python matplotlib with a line color gradient and colorbar
<p>I've been toying around with this problem and am close to what I want but missing that extra line or two. </p>

<p>Basically, I'd like to plot a single line whose color changes given the value of a third array. Lurking around I have found this works well (albeit pretty slowly) and represents the problem </p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
c = np.arange(1,100)
x = np.arange(1,100)
y = np.arange(1,100)

cm = plt.get_cmap('hsv')

fig = plt.figure(figsize=(5,5))
ax1 = plt.subplot(111)

no_points = len(c)
ax1.set_color_cycle([cm(1.*i/(no_points-1)) 
                     for i in range(no_points-1)])

for i in range(no_points-1):
    bar = ax1.plot(x[i:i+2],y[i:i+2])
plt.show()
</code></pre>

<p>Which gives me this:</p>

<p><a href="https://i.stack.imgur.com/6v86R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6v86R.png" alt="Single line with a color change"></a></p>

<p>I'd like to be able to include a colorbar along with this plot. So far I haven't been able to crack it just yet. Potentially there will be other lines included with different x,y's but the same c, so I was thinking that a Normalize object would be the right path. </p>

<p>Bigger picture is that this plot is part of a 2x2 sub plot grid. I am already making space for the color bar axes object with matplotlib.colorbar.make_axes(ax4), where ax4 with the 4th subplot. </p>