我正在做一个随机生成的世界,我从基本图形开始尝试与柏林噪声类似。我做了所有事情,我写的最后一件事(重要的一件事)确实有效。import mathimport randomimport matplotlib.pyplot as pltprint('ur seed')a = input()seed = int(a)b = (math.cos(seed) * 100)c = round(b)# print(c)for i in range(10): z = (random.randint(-1, 2)) change = (z + c) gener = [] gener.append(change) time = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] #print(gener) #print(change) plt.ylabel('generated') plt.xlabel('time') #Here I wanna add them to the graph and it is Erroring a lot plt.scatter(time, gener) plt.title('graph') plt.show()
1 回答
HUH函数
TA贡献1836条经验 获得超4个赞
问题是您设置gener为[]循环内而不是循环外。另外,您也不需要time循环内的变量。
改变
for i in range(10):
z = (random.randint(-1, 2))
change = (z + c)
gener = []
gener.append(change)
time = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
到
gener = []
for i in range(10):
z = (random.randint(-1, 2))
change = (z + c)
gener.append(change)
time = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
添加回答
举报
0/150
提交
取消