|
发表于 2020-3-8 16:45:16
|
显示全部楼层
- import numpy as np
- import matplotlib
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- import random as r
- class People():
- def __init__(self):
- self.x = r.randint(0,15)
- self.y = r.randint(0,15)
- # def move(self):
- # self.endx = self.x + r.choice(-1, 1)
- # self.endy = self.y + r.choice(-1, 1)
- #self.x = self.endx
- # self.y = self.endy
-
- def update_points(num):
- '''
- 更新数据点
- '''
- point_ani[0].set_data(mannumber[num].x + r.choice((-1, 1)), mannumber[num].y + r. choice((-1, 1)))
- return point_ani
- fig = plt.figure(tight_layout=True)
- plt.figure(num='图', figsize=(6, 4), dpi=120, facecolor='w', edgecolor='k')
- plt.axis((-1, 16, -1, 16), 1)
- mannumber = []
- for i in range(0, 100):
- a = People()
- mannumber.append(a)
- for i in range(0, 100):
- point_ani = plt.plot(mannumber[i].x, mannumber[i].y, 'bo')
- ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=100, blit=True)
- ani.save('aaaa.gif', writer='imagemagick', fps=10)
- plt.show()
复制代码 |
|