In [41]:
import numpy as np
from math import sin,pi

filedata = np.loadtxt('Input_withcolor.txt')

npoints = 58
def gencolor1(x): return 1300 - x*500/npoints
def gencolor2(x): return 2800 - 500 * sin(x*pi/float(npoints))
    
newdata = [ row[0:4].tolist() + [gencolor2(row[0]), gencolor1(row[0]), 0, 0] for row in filedata ]

np.savetxt('Input_funnycolor.txt', newdata, fmt="%.3f")

In [36]:
def gencolor1(x): return 1300 - x*500/npoints
def gencolor2(x): return 2800 - 500 * sin(x*pi/float(npoints))
    
newdata = [ row[0:4].tolist() + [gencolor1(row[0]), gencolor2(row[0]), 0, 0] for row in filedata ]


Out[36]:
[[0.0, 3830.0, 61.886993, 0.5, 1300.0, 2800.0, 0, 0],
 [1.0, 3791.0, 61.5711, 0.5, 1297.5, 2792.1463413440897, 0, 0],
 [2.0, 3681.0, 60.671246, 0.5, 1295.0, 2784.2946204609357, 0, 0],
 [3.0, 3605.0, 60.041653, 0.5, 1292.5, 2776.4467746451787, 0, 0],
 [4.0, 3815.0, 61.765686, 0.5, 1290.0, 2768.6047402353433, 0, 0],
 [5.0, 3785.0, 61.522354, 0.5, 1287.5, 2760.7704521360774, 0, 0],
 [6.0, 3733.0, 61.09828, 0.5, 1285.0, 2752.945843340743, 0, 0],
 [7.0, 3889.0, 62.361847, 0.5, 1282.5, 2745.1328444544774, 0, 0],
 [8.0, 3762.0, 61.335144, 0.5, 1280.0, 2737.3333832178478, 0, 0],
 [9.0, 3725.0, 61.03278, 0.5, 1277.5, 2729.549384031209, 0, 0]]

In [14]:
from math import sin,pi


xdata = range(npoints)
ydata = [ 2800 - 500 * sin(x*pi/float(npoints)) for x in xdata]

In [15]:
import matplotlib.pyplot as plt
%matplotlib inline

plt.plot(xdata, ydata)


Out[15]:
[<matplotlib.lines.Line2D at 0x7f1063ee3dd0>]

In [22]:
range(5)


Out[22]:
[0, 1, 2, 3, 4]

In [34]:
np.zeros(5) + [1, 2]


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-34-387e07737060> in <module>()
----> 1 np.zeros(5) + [1, 2]

ValueError: operands could not be broadcast together with shapes (5,) (2,) 

In [33]:
[0, 1] + [2, 3]


Out[33]:
[0, 1, 2, 3]

In [ ]: