鱼C论坛

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

制作病毒传播模拟的gif

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

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

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

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

如图,现在怎么制作gif?我用animation的但是报错了
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.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('work/sin_testm.gif', writer='imagemagick', fps=10)

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

使用道具 举报

发表于 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()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-25 04:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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