我正在做一個隨機生成的世界,我從基本圖形開始嘗試與柏林噪聲類似。我做了所有事情,我寫的最后一件事(重要的一件事)確實有效。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函數(shù)
TA貢獻1836條經(jīng)驗 獲得超4個贊
問題是您設置gener為[]循環(huán)內(nèi)而不是循環(huán)外。另外,您也不需要time循環(huán)內(nèi)的變量。
改變
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
提交
取消