import random import operator import matplotlib.pyplot import matplotlib.animation num_of_agents = 10 num_of_iterations = 100 agents = [] fig = matplotlib.pyplot.figure(figsize=(7, 7)) ax = fig.add_axes([0, 0, 1, 1]) #ax.set_autoscale_on(False) # Make the agents. for i in range(num_of_agents): agents.append([random.randint(0,100),random.randint(0,100)]) def update(frame_number): fig.clear() for i in range(num_of_agents): if random.random() < 0.5: agents[i][0] = (agents[i][0] + 1) % 99 else: agents[i][0] = (agents[i][0] - 1) % 99 if random.random() < 0.5: agents[i][1] = (agents[i][1] + 1) % 99 else: agents[i][1] = (agents[i][1] - 1) % 99 for i in range(num_of_agents): matplotlib.pyplot.scatter(agents[i][0],agents[i][1]) print(agents[i][0],agents[i][1]) animation = matplotlib.animation.FuncAnimation(fig, update, interval=1) matplotlib.pyplot.show()