[英]Python TypeError: takes 4 positional arguments but 5 were given
[英]Python: TypeError: draw() takes 0 positional arguments but 1 was given
我正在玩游戏,我想拥有一个窗口(在我的代码中称为Grid),该窗口刷新了第二个Grid(称为SecGrid)信息
import numpy as np
import pylab as pl
from random import randint
i = 0
o = 0
#Chose Grid size
m = int(input("Enter the width and length of the Grid: ",))
n = m
print("Your Grid will be",m,"x",n)
Grid = np.zeros((m+2,n+2))
SecGrid = np.zeros((m+2,n+2))
#Random /Grid filling in
while(i <= n/3*m):
i = i+1
Grid[randint(1,m), randint(1,n)] = 1
img = pl.imshow(Grid, cmap = 'PuRd', interpolation = 'none')
#Main algo
while (o < 2):
print(o)
v = input("continue: ")
o = o + 1
for i in range(1,m):
for j in range(1,n):
#Nbr of entities
nbr = 0
for k in range(-1,1):
for l in range(-1,1):
nbr = nbr + Grid[i+k,j+l]
#cells that are alive
if Grid[i,j] == 1:
if nbr > 1 and nbr < 4:
SecGrid[i,j] = 1
else:
SecGrid[i,j] = 0
#cells that are dead
else:
if nbr == 3:
SecGrid[i,j] = 1
else:
SecGrid[i,j] = 0
如何使用新信息刷新网格?
我试过了
Grid = SecGrid
pl.draw(img)
img.set_data(Grid)
但是我是python的新手,所以我不知道._。 请帮助我:3
pylab draw方法不带任何参数。 看看从命令行运行python的绘图文档。
For example:
$ python
>>> import pylab as pl
>>> help(pl.draw)
关于您的问题“如何用新信息刷新我的网格?”,因为您正在更新“随机/网格填充”注释下方的网格中的值,所以我假设您询问如何更新img中的数据宾语。 如果是这样,请参见以下内容:
# Note: entered in your code line by line into python at command line then
>>> help(img.set_data)
Help on method set_data in module matplotlib.image:
set_data(self, A) method of matplotlib.image.AxesImage instance
Set the image array
ACCEPTS: numpy/PIL Image A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.