2017-02-07 42 views
1

這是我第一次發佈。我對Python真的很陌生,幾乎在幾周前剛開始上課。我正在讀取一個包含(x,y)座標的Excel文件,在讀完它之後,我將不得不相應地繪製點。通過使用Turtle讀取Excel座標來繪製點圖

我已經爲我的點做了一個函數,讀取文件並將它們分成兩個列表x []和y []。我無法將x,y值從我的x []和y []傳遞到我的dot()函數。

我在網上搜索了類似的問題,但沒有運氣,我相信這是由於我在編程方面經驗不足。希望得到你們的一些提示。

我已在下面發佈我的代碼。

非常感謝。

import turtle 


def dot(x, y): 
t = turtle.Turtle() 
t.pensize(2) 
t.up() 
t.goto(x, y) 
t.color("red") 
t.down() 
t.begin_fill() 
t.circle(25) 
t.color("red") 
t.end_fill() 
turtle.done() 


def a(): 
x, y = [], [] 
handle = open("SineWave.csv") 
for line in handle: 
    line = line.rstrip() 
    line = line.split(",") 
    x.append(line[0]) 
    y.append(line[1]) 
    x = [int(n) for n in x] 
    y = [int(n) for n in y] 
i = 0 
while i < len(x): 
    print (x[i]) 
    i += 1 


def b(): 
x, y = [], [] 
handle = open("SineWave.csv") 
for line in handle: 
    line = line.rstrip() 
    line = line.split(",") 
    x.append(line[0]) 
    y.append(line[1]) 
    x = [int(n) for n in x] 
    y = [int(n) for n in y] 
i = 0 
while i < len(y): 
    print(y[i]) 
    i += 1 

dot(a(),b()) 

回答

0

您的代碼看起來有點亂,有些塊重複,有些塊丟失。下面是我對你想要做的事情的近似。不幸的是,你沒有提供任何樣本數據,所以我不能真正完成的代碼,並顯示它會輸出:

from turtle import Turtle, Screen 

def read_points(): 
    handle = open("SineWave.csv") 

    points = [] 

    for line in handle: 
     my_x, my_y = line.rstrip().split(",") 
     points.append((float(my_x), float(my_y))) 

    return points 

points = read_points() 

yertle = Turtle(visible=False) 
yertle.up() 
yertle.color("red") 

for point in points: 
    yertle.goto(point) 
    yertle.dot(10) 

screen = Screen() 
screen.exitonclick() 

一旦你安裝你的數據上面,並讓它運行,你可能想要了解海龜方法setworldcoordinates(),這將允許您調整窗口的座標系,以更好地適應您工作的數據。

+0

非常感謝,我會慢慢看這個。 –

相關問題