如何为matplotlib动画

时间:2017-10-19 03:28:39

标签: python-3.x

我无法为matplotlib动画添加标签和标题。 请在下面找到我的代码

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import time
%matplotlib inline
style.use("ggplot")
fig = plt.figure() 
ax1 = fig.add_subplot(1,1,1)

def animate(i): 
    pullData = open("twitter-out.txt","r").read()
    lines = pullData.split('\n')

xar = []
yar = []
x = 0
y = 0

for l in lines[-200:]:
    x += 1
    if "pos" in l:
        y += 1
    elif "neg" in l:
        y -= 1

    xar.append(x)
    yar.append(y)

ax1.clear()
ax1.plot(xar,yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()

0 个答案:

没有答案