newGrid = grid.copy()
"""
  do your updating. this needs to be done on a copy of 'grid' because you are
  updating element-by-element, and updates to previous rows/columns will
  affect the result at 'grid[i,j]' if you don't use a copy
  """
mat.set_data(newGrid)
grid = newGrid
Python matplotlib — обновление данных во время анимации в игре Conway’s Game of Life