鱼C论坛

 找回密码
 立即注册
查看: 791|回复: 1

制作病毒传播模拟的gif

[复制链接]
发表于 2020-3-8 16:08:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 一个账号 于 2020-3-8 16:53 编辑

如图,现在怎么制作gif?我用animation的但是报错了


  1. import numpy as np
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4. import matplotlib.animation as animation
  5. import random as r
  6. class People():
  7.     def __init__(self):
  8.         self.x = r.randint(0,15)
  9.         self.y = r.randint(0,15)
  10.    # def move(self):
  11.        # self.endx = self.x + r.choice(-1, 1)
  12.        # self.endy = self.y + r.choice(-1, 1)
  13.         #self.x = self.endx
  14.        # self.y = self.endy
  15.         
  16. def update_points(num):
  17.     '''
  18.     更新数据点
  19.     '''
  20.     point_ani.set_data(mannumber[num].x + r.choice(-1, 1), mannumber[num].y + r. choice(-1, 1))
  21.     return point_ani
  22. fig = plt.figure(tight_layout=True)
  23. plt.figure(num='图', figsize=(6, 4), dpi=120, facecolor='w', edgecolor='k')
  24. plt.axis((-1, 16, -1, 16), 1)
  25. mannumber = []
  26. for i in range(0, 100):
  27.     a = People()
  28.     mannumber.append(a)
  29. for i in range(0, 100):
  30.     point_ani = plt.plot(mannumber[i].x, mannumber[i].y, 'bo')

  31. ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=100, blit=True)
  32. ani.save('work/sin_testm.gif', writer='imagemagick', fps=10)

  33. plt.show
复制代码
001.jpg
00.jpg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-8 16:45:16 | 显示全部楼层

  1. import numpy as np
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4. import matplotlib.animation as animation
  5. import random as r
  6. class People():
  7.     def __init__(self):
  8.         self.x = r.randint(0,15)
  9.         self.y = r.randint(0,15)
  10.    # def move(self):
  11.        # self.endx = self.x + r.choice(-1, 1)
  12.        # self.endy = self.y + r.choice(-1, 1)
  13.         #self.x = self.endx
  14.        # self.y = self.endy
  15.         
  16. def update_points(num):
  17.     '''
  18.     更新数据点
  19.     '''
  20.     point_ani[0].set_data(mannumber[num].x + r.choice((-1, 1)), mannumber[num].y + r. choice((-1, 1)))
  21.     return point_ani
  22. fig = plt.figure(tight_layout=True)
  23. plt.figure(num='图', figsize=(6, 4), dpi=120, facecolor='w', edgecolor='k')
  24. plt.axis((-1, 16, -1, 16), 1)
  25. mannumber = []
  26. for i in range(0, 100):
  27.     a = People()
  28.     mannumber.append(a)
  29. for i in range(0, 100):
  30.     point_ani = plt.plot(mannumber[i].x, mannumber[i].y, 'bo')

  31. ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=100, blit=True)
  32. ani.save('aaaa.gif', writer='imagemagick', fps=10)

  33. plt.show()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-2 11:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表