here goes my first ever question, im doing a basic logplayer from data in a txt file:
the code is something like:
for aircraft in self.logArray.itervalues():
for logLine in aircraft:
currentPoint = self.point(logLine[1], logLine[2])
currentPoint = self.win2canvas(currentPoint)
points = np.append(points, currentPoint)
print points
print np.size(points)
self.canvas.create_line(points)
points = np.array([])
So logArray is a dictionary, each name contains an array of kind [time,x,y], so there will be an array like that for each aircraft name.
The second for simply converts to tkinter canvas coords and appends the currentPoint to the pre-existing (and initialized).
When it gets to the create_line method, i get:
File "/home/joao/tese/workspace/ATC/src/autoATC/LogPlayer.py", line 131, in drawPath
self.canvas.create_line(points)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2204, in create_line
return self._create('line', args, kw)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2192, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: wrong # coordinates: expected an even number, got 399
I’ve manually checked the size of the points array and is indeed even numbered. So i double-checked using np.size, which returned 398!
I’ve also tried using a very similar test approach, doing:
self.canvas.create_line([123,345,234,453,23,34,45,56,67,78])
which went perfectly! I don’t get why, but somehow my points array ends up getting an extra element, and I don’t know where from!
Thank you for your time and patience!
I believe that the issue is that you are using numpy arrays for this. The call stack here looks like this
create_line return
self._create(‘line’, args, kw)
*(args + self._options(cnf, kw))))
return array2string(a,
max_line_width, precision,
suppress_small, ‘ ‘, “”, str)
array2string return lst
If you have np.array([0., 0., 200., 100.]) the string that is returned by array2string() is ‘[ 0. 0. 100. 200.]’. I suspect that then it gets split returning the list of [‘[‘, ‘0.’, ‘0.’, ‘100.’, ‘200.]’] which has one extra element ‘[‘.
You code should work if you use a list in place of np.array() or even if you just cast the numpy array to a list, like:
Although, I would think that using a list from the start is more straight forward if you don’t need to use the functionality of numpy arrays.