创建实时条形图

问题描述

我无法使用实时条形图。 来自 twitter 的传入数据如下所示(文件内的数据):

Snake: 5
Code: 3
Python: 7

这是当前尝试绘制文件代码

import matplotlib.pyplot as plt 
import matplotlib.animation as animation 
import time

fig = plt.figure() 
ax1 = fig.add_subplot(1,1,1)

def animate(i):
    pullData = open("wordsToGraph.txt","r").read()
    dataArray = pullData.split('\n')
    xar = []
    yar = []  for eachLine in dataArray:  
        if len(eachLine)>1:
            x,y = eachLine.split(':')
            xar.append(str(x))
            yar.append(int(y))
    ax1.clear()
    ax1.bar(xar,yar)
    ani = animation.FuncAnimation(fig, animate, interval=1000)
    plt.show()

输出错误

TypeError: animate() missing 1 required positional argument: 'i'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)