这是我第一次发帖。我对Python很陌生,几周前刚开始上课。我正在尝试读取包含(x,y)坐标的Excel文件,在阅读之后,我将不得不相应地绘制点。
我为我的点创建了一个函数,读取文件并将它们分成两个列表x []和y []。我将x [Y]和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 :(得分: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()
一旦你将数据安装到上面并使其运行,你可能想要了解一下turtle方法setworldcoordinates()
,这将允许你调整窗口的坐标系以更好地适应数据你正在工作。