I have a python-script which should read values from a txt-file, process a backup of them, and then plot them. The code is as following:
class fit_to_init_values:
def __init__(self, filename):
lines = tuple(open(filename, 'r'))
self.arr = []
self.xdata = []
self.xdata_old = []
self.ydata = []
self.ydata_old = []
print len(lines)
for elem in lines:
a = elem.split(", ")
if len(a) == 3:
data = data_point(float(a[0]), float(a[1]))
self.arr.append(data)
else:
print len(a)
for elem in self.arr:
self.xdata.append(elem.x)
self.ydata.append(elem.y)
self.xdata_old = self.xdata
print self.xdata[0]
self.ydata_old = self.ydata
def reduce_stuff(self):
idx = self.ydata.index(max(self.ydata))
self.max1 = max(self.xdata)
tmp = self.xdata
for i, elem in enumerate(tmp):
tmp[i] = (tmp[i] - 1.254111749e14)/self.max1
print self.xdata[0]
def plot_data(self, num):
if num == 0:
plt.plot(self.xdata_old, self.ydata_old, 'bs')
print("Plot 0")
plt.show()
and it is called as:
test = fit_to_init_values("pulse1.txt")
test.reduce_stuff()
test.plot_data(0)
Now the output of this is:
4096
7.42611749e+13
-0.289578281623
Plot 0
what means that apparently self.xdata
got modified by the reduce_stuff()
-function. The same happens if I replace print self.xdata[0]
with print self.xdata_old[0]
. Why do these values change, even if I am never operating on them?
If necessary, I can also provide the file "pulse1.txt".