我有一个数据框
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.ticker as ticker
import matplotlib.ticker as mtick
d = {'Perc_Seats': [ 0,17,23,31,35,35,27,23,52,56.]}
idx= [1984, 1989, 1991, 1996, 1998, 1999, 2004, 2009, 2014, 2019]
df = pd.DataFrame(data=d,index=idx)
我试图为此编写动画图,我的脚本在下面
fig,ax1 = plt.subplots(figsize=(8,6))
ax1.set_position([0.2,0.05,0.75,0.9])
plt.xlim(1984, 2019)
plt.ylim(0,100)
plt.xlabel('Year',fontsize=20)
plt.ylabel("percent",fontsize=20)
plt.tick_params(labelsize=15)
plt.xticks(np.arange(1984, 2020, step=5))
fmt = '%.0f%%' # Format you want the ticks, e.g. '40%'
yticks = mtick.FormatStrFormatter(fmt)
ax1.yaxis.set_major_formatter(yticks)
plt.yticks(np.arange(0, 101, step=20))
ln1,=plt.plot([],[],"-*r")
def animate(frame):
for a in range (len(df)):
data1 = df.iloc[:frame+1]
ln1.set_data(data1.index,data1.values)
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=10, repeat=True)
plt.show()
我想在绘制年份时进行计算,我想分别在点(*)上写出每年的百分比值