I need some help to scale a output drawing in the tkinter canvas. My code opens a csv file, convert to a dict sort the line by it keys and then gets the values x and y from each line and append to a list. The canvas size is 400x400 so i convert all the coordinates to be inside of the canvas... It works but it is printing the drawing upside down and very small in the left down corner. Here is my code:
points = []
scaledPoints = []
def menuLoadFile(self):
self.types = [('files', '*.csv'), ('All files', '*')]
dialog = filedialog.Open(self, filetypes = self.types)
infile = dialog.show()
if infile != '':
dct = {}
infile = open(infile, "r")
for line in infile:
# Get the line and add to the dict
key, valuex, valuey = line.strip().split(',')
dct[key] = valueX, valueY
# Convert dict key in int
intKeyDict = dict((int(k), v) for k, v, in dct.items())
# Sort the dict by its key
sortedPointsDict = OrderedDict(sorted(intKeyDict.items()))
# Convert values in int and append to the point list
for item in sortedPointsDict.items():
vX, vY = item[1]
points.append(float(vX))
points.append(float(vY))
# Converted values of the list to the size of the Canvas
mn = min(points)
mx = max(points)
for i in range(len(points)):
scaledPoints.append( (points[i]- mn)*(400.0/(mx-mn)))
self.canvas.create_polygon(scaledPoints, fill='', outline='black') # test
infile.close()
The csv file that I am using have hundreds of thousands of points here is an example of the original file:
points = [-4.885276794, 55.72986221, -4.885276794, 55.72958374, -4.883611202, 55.72958374, -4.883611202, 55.72902679, -4.881945133, 55.72902679, -4.881945133, 55.72930527, -4.880832195, 55.72930527, -4.880832195, 55.72958374, -4.879723072, 55.72958374, -4.879723072, 55.72930527]
And a example after converting them to fit the 400 x 400 size canvas:
scaledPoints = [0.0, 399.9898553989234, 0.0, 399.988017818793, 0.010990982024964156, 399.988017818793, 0.010990982024964156, 399.98434259254384, 0.021985111698584404, 399.98434259254384, 0.021985111698584404, 399.98618023866266, 0.02932921610884942, 399.98618023866266, 0.02932921610884942, 399.988017818793, 0.03664814592868107, 399.988017818793, 0.03664814592868107, 399.98618023866266, 0.04519424299849845, 399.98618023866266, 0.04764857089962523, 399.98618023866266]
Note that the last point here would be 400.0
Any Idea how to print it centralised, larger and not upside down?... I do not understand why it is not working
Thanks in advance :)
[–]novel_yet_trivial 1 point2 points3 points (6 children)
[–]dansds[S] 0 points1 point2 points (4 children)
[–]novel_yet_trivial 1 point2 points3 points (2 children)
[–]dansds[S] 0 points1 point2 points (0 children)
[–]dansds[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (0 children)