我需要在 python turtle 中制作一个有 100000 个点的图表来绘制
I need to make a graph in python turtle with 100000 points to plot
我必须制作一个 python 具有 100000 个点的海龟折线图。我不需要 x 或 y 轴上的任何数字。所有 y 轴位置都在名为 C_txt_list 的列表中。到目前为止,我有一些代码可以打印 C_txt_list 中的每个值。 C_txt_list 只是从 0 到 100 的值。
# re-opens Rand_Numbers but the complete version and in read mode
C_txt = open("Rand_Numbers", "r")
# reads each line of C_txt and adds it to a list
with C_txt as File:
C_txt_list = C_txt.readlines()
C_txt_list = [lines.strip() for lines in C_txt_list]
# prints each element in C_txt_list
index_Num = 0
while index_Num != repeats:
print(C_txt_list[index_Num])
index_Num += 1
我还需要图表适合 window 1500p x 800p。任何帮助表示赞赏。
turtle.screensize(canvwidth=None, canvheight=None, bg=None)
turtle.screensize(1500,800) //for your issue.
这是一个粗略的例子,应该按照您的描述进行操作:
from turtle import Screen, Turtle
screen = Screen()
screen.setup(1500, 800)
screen.screensize(100_000, 800)
screen.tracer(False)
turtle = Turtle()
turtle.hideturtle()
turtle.penup()
with open("Rand_Numbers") as file:
for x, line in enumerate(file, start=-50_000):
y = int(line) # int() deals with the whitespace/newline
turtle.goto(x, y)
turtle.pendown() # needed after 1st point
screen.tracer(True)
screen.exitonclick()
请注意 window 底部的滚动条,以查看我编写此代码生成的 "data" 的其余部分:
from random import randint
with open("Rand_Numbers", 'w') as file:
for x in range(100_000):
y = randint(0, 100)
print(y, file=file)
一边
这个问题在 Python turtle 中出现了一个烦人的故障。我想从 0 开始枚举数据,而不是 -50,000 所以我尝试修改坐标系以匹配数据:
screen.setup(1500, 800)
screen.setworldcoordinates(0, -400, 1500, 400)
screen.screensize(100_000, 800)
但是,通过它们的实现,screensize()
撤消了 setworldcoordinates()
的工作,而 setworldcoordinates()
撤消了 screensize()
的工作。所以无论你按什么顺序调用它们,这都是行不通的!
我必须制作一个 python 具有 100000 个点的海龟折线图。我不需要 x 或 y 轴上的任何数字。所有 y 轴位置都在名为 C_txt_list 的列表中。到目前为止,我有一些代码可以打印 C_txt_list 中的每个值。 C_txt_list 只是从 0 到 100 的值。
# re-opens Rand_Numbers but the complete version and in read mode
C_txt = open("Rand_Numbers", "r")
# reads each line of C_txt and adds it to a list
with C_txt as File:
C_txt_list = C_txt.readlines()
C_txt_list = [lines.strip() for lines in C_txt_list]
# prints each element in C_txt_list
index_Num = 0
while index_Num != repeats:
print(C_txt_list[index_Num])
index_Num += 1
我还需要图表适合 window 1500p x 800p。任何帮助表示赞赏。
turtle.screensize(canvwidth=None, canvheight=None, bg=None)
turtle.screensize(1500,800) //for your issue.
这是一个粗略的例子,应该按照您的描述进行操作:
from turtle import Screen, Turtle
screen = Screen()
screen.setup(1500, 800)
screen.screensize(100_000, 800)
screen.tracer(False)
turtle = Turtle()
turtle.hideturtle()
turtle.penup()
with open("Rand_Numbers") as file:
for x, line in enumerate(file, start=-50_000):
y = int(line) # int() deals with the whitespace/newline
turtle.goto(x, y)
turtle.pendown() # needed after 1st point
screen.tracer(True)
screen.exitonclick()
请注意 window 底部的滚动条,以查看我编写此代码生成的 "data" 的其余部分:
from random import randint
with open("Rand_Numbers", 'w') as file:
for x in range(100_000):
y = randint(0, 100)
print(y, file=file)
一边
这个问题在 Python turtle 中出现了一个烦人的故障。我想从 0 开始枚举数据,而不是 -50,000 所以我尝试修改坐标系以匹配数据:
screen.setup(1500, 800)
screen.setworldcoordinates(0, -400, 1500, 400)
screen.screensize(100_000, 800)
但是,通过它们的实现,screensize()
撤消了 setworldcoordinates()
的工作,而 setworldcoordinates()
撤消了 screensize()
的工作。所以无论你按什么顺序调用它们,这都是行不通的!