简体   繁体   中英

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

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 ._. pls help meh :3

The pylab draw method does not take any arguments. Take a look at the draw documentation running python from the command line.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM