先尝试以下代码,如果成功就可以继续吧
import numpy as np #数组
import matplotlib.pyplot as plt #生成动画
import matplotlib.animation as animation #更新模拟
x = np.array([[0,0,255],[255,255,0],[0,255,0]])#三维数组
plt.imshow(x, interpolation='nearest')#nearest输出尖锐边缘
plt.show()#将矩形输出为图像
最后代码:源码:https://github.com/electronut/pp
"""
conway.py
A simple Python/matplotlib implementation of Conway's Game of Life.
Author: Mahesh Venkitachalam
"""
import sys, argparse
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
ON = 255
OFF = 0
vals = [ON, OFF]
def randomGrid(N):
"""returns a grid of NxN random values"""
return np.random.choice(vals, N*N, p=[0.2, 0.8]).reshape(N, N)
def addGlider(i, j, grid):
"""adds a glider with top left cell at (i, j)"""
glider = np.array([[0, 0, 255],
[255, 0, 255],
[0, 255, 255]])
grid[i:i+3, j:j+3] = glider
def addGosperGliderGun(i, j, grid):
"""adds a Gosper Glider Gun with top left cell at (i, j)"""
gun = np.zeros(11<