2

I have a set of points from which I am getting a spline curve, but it includes color values, which I would like to smoothly vary along the curve.

Right now I am using Matplotlib, so a solution in that would be preferable. But if this is super easy with some other Python library, I don't mind switching to it. OpenGL seemed a bit overkill.

Here's an example:

n = 50
x = np.array(list(range(0,n))) * 0.1
y = x**2 + np.random.randn(n) * 2.0
c1,c2,c3 = zip(*np.random.uniform(low=0.0,high=1.0,size=(n,3)))
print(  "\n".join( map(lambda x: str(x), [n,x,y,c1,c2,c3]) )  )
tck, u = interpolate.splprep([x,y,c1,c2,c3],k=3)
out = interpolate.splev(u,tck)
plt.figure()
plt.plot(out[0],out[1])
plt.show()

So I get the x and y values of the points, and then the RGB values inc1,c2,c3. Right now I am just plotting the curve resulting from the points. How can I add a smoothly varying color to it?

user3658307
  • 761
  • 1
  • 7
  • 23
  • Take a look at https://matplotlib.org/examples/pylab_examples/multicolored_line.html; the second plot shows the color varying smoothly. – Warren Weckesser Aug 15 '17 at 04:20

0 Answers0