![](/img/trans.png)
[英]How to change the Y scale for my plot graph in matplotlib.pyplot
[英]Pyplot Not Displaying My Graph
我正在嘗試將recaman序列繪制為散點圖,據我所知我的腳本已正確設置。 另外,我可以確定它不是后端,因為我可以運行以下腳本:
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()
代替在循環中繪制單個不可見點,可以使用plt.plot(xaxis,yaxis)
或(更好) plt.scatter(xaxis,yaxis)
plt.plot(xaxis,yaxis)
繪制整個曲線。
如果您希望繪制單個點,則至少使它們可見:
for i in range (0,itterations):
plt.plot(xaxis[i],yaxis[i],"o")
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.