简体   繁体   English

Python:TypeError:draw()接受0个位置参数,但给出了1个

[英]Python: TypeError: draw() takes 0 positional arguments but 1 was given

I'm making the game of life and I want to have a window (in my code called Grid) that is refreshing with the 2nd Grid (called SecGrid) information 我正在玩游戏,我想拥有一个窗口(在我的代码中称为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

How can I refresh my grid with new information ? 如何使用新信息刷新网格?

I tried this 我试过了

Grid = SecGrid
pl.draw(img)
img.set_data(Grid)

But I new to python so I have no clue ._. 但是我是python的新手,所以我不知道._。 pls help meh :3 请帮助我:3

The pylab draw method does not take any arguments. pylab draw方法不带任何参数。 Take a look at the draw documentation running python from the command line. 看看从命令行运行python的绘图文档。

For example:
$ python
>>> import pylab as pl
>>> help(pl.draw)

In regards to your question "How can I refresh my grid with new information ?", as you are updating values in your Grid below your "Random /Grid filling in" comment I will assume that your asking how to update that data in your img object. 关于您的问题“如何用新信息刷新我的网格?”,因为您正在更新“随机/网格填充”注释下方的网格中的值,所以我假设您询问如何更新img中的数据宾语。 If so, see the following: 如果是这样,请参见以下内容:

# 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.

相关问题 Python TypeError:接受 4 个位置参数,但给出了 5 个 - Python TypeError: takes 4 positional arguments but 5 were given TypeError:取 0 位置 arguments 但给出 1 - TypeError: takes 0 positional arguments but 1 was given python super:TypeError:__init __()接受2个位置参数,但给出了3个 - python super :TypeError: __init__() takes 2 positional arguments but 3 were given Python 数据集更新 - TypeError: update() 最多需要 2 个位置参数(给出 3 个) - Python dataset update - TypeError: update() takes at most 2 positional arguments (3 given) Python/MySQL TypeError:execute() 需要 2 到 4 个位置参数,但给出了 5 个 - Python/MySQL TypeError: execute() takes from 2 to 4 positional arguments but 5 were given 如何修复 Python 中的“TypeError: MOVE() 需要 0 个位置参数,但给出了 1 个” - How to fix 'TypeError: MOVE() takes 0 positional arguments but 1 was given' in Python TypeError: with_column() 从 3 到 4 个位置 arguments 但给出了 5 个(python) - TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given (python) Using Map function with Lambda in Python: TypeError: () takes 0 positional arguments but 1 was given - Using Map function with Lambda in Python: TypeError: () takes 0 positional arguments but 1 was given Python TypeError:衍生物_circ()接受2个位置参数,但给出了6个 - Python TypeError: derivatives_circ() takes 2 positional arguments but 6 were given TypeError:__init __()接受2个位置参数,但是给了3个Python 3? - TypeError: __init__() takes 2 positional arguments but 3 were given Python 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM