向Matplotlib动画图添加背景Gif或图像

时间:2019-03-13 02:45:45

标签: python pandas numpy matplotlib

我正在尝试在背景中向我的matplotlib图中添加gif或图像,但是它全部被压缩了。我一直在尝试将背景添加到动画图表中,但是我不确定问题是否出在我使用范围或其他方面。我尝试将范围更改为许多不同的数字,但似乎没有一个可以解决问题。还有其他我想念的东西吗?

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
from imageio import imread

img = imread("h.png") 
% or img = imread("h.gif) 
h_season=pd.read_html('2016_H.xls')
DF=(harden_season[0])
days=DF.iloc[:,0].values
m=DF.iloc[:,13].values


title = 'OD% Over the year'
x = np.array(days)
y = np.array(m)
overdose = pd.DataFrame(y,x)
print(overdose)
#XN,YN = augment(x,y,10)
#augmented = pd.DataFrame(YN,XN)
overdose.columns = {title}
#print(makes.size)

Writer = animation.writers['ffmpeg']
writer = Writer(fps=20, metadata=dict(artist='Me'), bitrate=1800)
fig = plt.figure(figsize=(10,6))
plt.imshow(img,zorder=0,  extent=[0, 0, 9, 6 ])

plt.xlim(1, 82)
plt.ylim(np.min(overdose)[0], np.max(overdose)[0])
plt.xlabel('Year',fontsize=20)
plt.ylabel(title,fontsize=20)
plt.title("OD",fontsize=20)
def animate(i):
    data = overdose.iloc[:int(i+1)] #select data range
    p = sns.lineplot(x=data.index, y=data[title], data=data, color="b")
    p.tick_params(labelsize=17)
    plt.setp(p.lines,linewidth=7)
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=100, repeat=True)
ani.save('ODJumpy2016.mp4', writer=writer)

graph mp4 file

0 个答案:

没有答案