安装相关的模块
首先第一步的话我们需要安装相关的模块,通过 pip
命令来安装
pip install gif
gif matplotlib plotly altair
pip install "gif[altair]"
pip install "gif[matplotlib]"
pip install
"gif[plotly]"
gif
和 matplotlib
的结合
我们先来看 gif
和 matplotlib
模块的结合,我们先来看一个简单的例子,代码如下
import random
from matplotlib import pyplot as plt
import gif
x = [random.randint(0, 100) for _ in range(100)]
y = [random.randint(0, 100) for _ in range(100)]
gif.options.matplotlib[ "dpi" ] = 300
@gif.frame
def plot(i):
xi = x[i*10:(i+1)*10]
yi = y[i*10:(i+1)*10]
plt.scatter(xi, yi)
plt.xlim((0, 100))
plt.ylim((0, 100))
frames = []
for i in range(10):
frame = plot(i)
frames.