【发布时间】:2020-10-12 06:48:43
【问题描述】:
首先我想分享csv文件的数据。
date, total_cases, total_deaths
12-5-2020,6,2
13-5-2020,7,3
14-5-2020,10,2
15-5-2020,18,5
现在我想制作一个动画比较图,其中 x 轴将绘制为 dates,y 轴将绘制为 total_cases 和 total_deaths。
from matplotlib import dates as mdate
from matplotlib import pyplot as plt
import matplotlib.animation as animation
import pandas as pd
m=pd.read_csv("covid-data.csv")
m['date']=pd.to_datetime(m['date'])
m.sort_values('date',inplace=True)
cdate=m['date']
ccase=m['total_cases']
cdeath=m['total_deaths']
fig = plt.figure()
ax1 = fig.add_subplot(111)
def animate(i):
ax1.clear()
ax1.plot(cdate,ccase)
ax1.plot(cdate,cdeath)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
现在 我无法获得我们想要的输出或动画。我该如何克服这个问题并找到解决方案?
对不起我的英语
【问题讨论】:
-
随着动画的运行,你希望看到什么变化?
标签: python pandas csv matplotlib animation