Я создаю анимацию matplotlib, но название не изменится.
Я пробовал и set_title, и set_text, но он покажет только последний заголовок в списке.
%matplotlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import animation
plt.rcdefaults()
x=range(0,3)
fig, ax = plt.subplots()
people = ['Dan', 'Jimmy','']
titleList=['Basketball','Hockey','Baseball']
frame=[[4,9,0],[2,6,0],[2,8,0]]
barcollection = plt.barh(x,frame[0])
ax.set_xlim([0,10])
ax.set_title("Project")
ax.set_xlabel("Knowledge Level")
title = plt.text(0.5,0.95, "Basketball", bbox={'facecolor':'r', 'alpha':0.5, 'pad':5},
transform=ax.transAxes, ha="center")
plt.yticks(np.arange(len(people)),people)
def animate(i):
while i<2:
y=frame[i+1]
print(y)
for i, b in enumerate(barcollection):
title.set_text(str(titleList[i]))
b.set_width(y[i])
anim=animation.FuncAnimation(fig,animate,repeat=False,blit=False,frames=3,
interval=2000)
anim.save('mymovie.mp4',writer=animation.FFMpegWriter(fps=.2))
plt.show()