样本数据:
Area Africa Asia Europe N_America S_America Australia Antarctica
Y1961 -0.17 0.49 8.74 0.17 1.16 1.51 2.80
Y1962 -0.40 -0.08 3.00 -0.58 -1.39 1.23 -2.27
Y1963 0.64 2.66 1.03 3.72 1.39 -1.14 1.35
Y1964 -1.53 -1.66 -5.23 -2.85 -2.17 -0.22 -3.66
Y1965 -1.97 -0.33 -4.30 -5.94 -0.15 1.27 -0.99
代码:
n=len(Continents.index)
fig,ax=plt.subplots()
def action(curr):
global colors
global cmap
global Continents
global color_dict
if curr==n:
a.event_source.stop()
CURR=Continents.iloc[curr]
ax = plt.gca()
ticks(curr)
bars = plt.bar(Continents.columns,CURR,color=[color_dict[country] for country in Continents.columns])
for bar,height in zip(bars,CURR):
return bar.set_height(height)
a = animation.FuncAnimation(fig,action, interval=100, frames=np.array(range(0,n)))
当我单独使用我的动作函数时,它可以工作,但我不能在 animation.Funcanimation() 函数中使用它。我想根据年份更改条形高度。