将背景图像添加到matplotlib图/ gif

问题描述

我有一个任务,需要多次调用绘图并根据结果创建gif(请参见下面的可重现示例)。

我的问题是:我想向此gif添加背景图像。我的猜测是,在追加之前,我必须将其添加到循环中的某个位置。

到目前为止,我发现的内容虽然很有趣,但与我的问题并没有真正的联系:

Plotting a cropped background image on a matplotlib graph

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import PillowWriter
import time

rng = np.random.default_rng()
fig = plt.figure(figsize=[10,9])

ims = []
for i in range(200):
    df = pd.DataFrame(rng.integers(0,100,size=(100,2)),columns=list('xy'))
    x = df["x"]
    y = df["y"]
    im = plt.plot(x,y,"b.")
    ims.append(im)
    print(i)
    
    
    

ani = animation.ArtistAnimation(fig,ims,interval=500,blit=True,repeat_delay=1000)

writer = PillowWriter(fps=2)
ani.save("demo2.gif",writer=writer)

来源:

How to create a DataFrame of random integers with Pandas?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)