Я пытаюсь создать анимированную гистограмму с помощью Matplotlib. Смогли продукт стати c сюжет. Нит умеет анимировать сериал. Может ли кто-нибудь помочь. Я чувствую, что с FuncAnimation что-то не так. Заранее благодарим.
Код ниже \\
fig, ax = plt.subplots(figsize=(15, 8))
def draw_barchart(Day):
df = pd.read_excel('C:/Users/Kedar/MEDD/District.xlsx')
df = df.sort_values(by='Day',ascending=True)
current_date = 37
dff = df[df['Day'].eq(current_date)].sort_values(by='Death_rate_new', ascending=True).tail(10)
# dff = dff[::-1] # flip values from top to bottom
ax.clear()
ax.barh(dff['Area'], dff['Death_rate_new'], color=colors)
# iterate over the values to plot labels and values (Tokyo, Asia, 38194.2)
for i, (value, name) in enumerate(zip(dff['Death_rate_new'], dff['Area'])):
ax.text(value, i, value, ha='left') # 38194.2: value
# Add date right middle portion of canvas
#ax.text(1, 0.4, current_date, transform=ax.transAxes, size=46, ha='right')
# ... polished styles
ax.text(1, 0.4, current_date, transform=ax.transAxes, color='#777777', size=46, ha='right', weight=800)
ax.text(0, 1.06, 'Death rate (%)', transform=ax.transAxes, size=12, color='#777777')
ax.xaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}'))
ax.xaxis.set_ticks_position('top')
ax.tick_params(axis='x', colors='#777777', labelsize=12)
ax.set_yticks(['Area'])
ax.margins(0, 0.01)
ax.grid(which='major', axis='x', linestyle='-')
ax.set_axisbelow(True)
ax.text(0, 1.12, 'Death Rate for Major Municipal Corporation in Maharasthra from 4th April to 25th May',
transform=ax.transAxes, size=24, weight=600, ha='left')
ax.text(1, 0, 'by @kedarpatgaonkar; credit @pratapvardhan', transform=ax.transAxes, ha='right',
color='#777777', bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
plt.box(False)
draw_barchart(37)
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
fig, ax = plt.subplots(figsize=(15, 8))
animator = animation.FuncAnimation(fig, draw_barchart, frames=range(1,37))
HTML(animator.to_jshtml())
\\