我正在尝试将recaman sequence绘制成散点图,据我所知我的脚本已正确设置。另外,我非常确定它不是后端,因为我可以运行以下脚本:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
,效果很好。这是我的代码:
import matplotlib.pyplot as plt
import os
while(True):
try:
itterations = int(input("Itterations: "))
break
except ValueError:
os.system("cls")
def recaman(n):
arr = [0] * n
arr[0] = 0
for i in range(1, n):
curr = arr[i-1] - i
for j in range(0, i):
if ((arr[j] == curr) or curr < 0):
curr = arr[i-1] + i
break
arr[i] = curr
return(arr)
def genX(n):
x = []
for i in range(0,n):
i += 1
x.append(i)
return(x)
xaxis = genX(itterations)
yaxis = recaman(itterations)
for i in range (0,itterations):
plt.plot(xaxis[i],yaxis[i])
plt.show()
答案 0 :(得分:0)
使用plt.plot(xaxis,yaxis)
或(更好)plt.scatter(xaxis,yaxis)
绘制整个曲线,而不是在循环中绘制单个不可见点。
如果您希望绘制单个点,至少要使它们可见:
for i in range (0,itterations):
plt.plot(xaxis[i],yaxis[i],"o")
plt.show()