Python 使用matplotlib打印实时数据
我试图使用Python 使用matplotlib打印实时数据,python,matplotlib,Python,Matplotlib,我试图使用matplotlib制作图形。它显示错误: ani=animation.FuncAnimation(f,animate, interval=1000) File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\animation.py", line 1703, in __init__ TimedAnimation.__init__(self, fig, **kw
matplotlib
制作图形。它显示错误:
ani=animation.FuncAnimation(f,animate, interval=1000)
File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\animation.py", line 1703, in __init__
TimedAnimation.__init__(self, fig, **kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\animation.py", line 1465, in __init__
event_source = fig.canvas.new_timer()
AttributeError: 'NoneType' object has no attribute 'new_timer'
我的代码:
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
def animate(i):
pullData=open("ip.txt","r").read()
dataList= pullData.split('\n')
xList=[]
yList=[]
for eachLine in dataList:
if len(eachLine)>1:
x,y=eachLine.split(',')
xList.append(int(x))
yList.append(int(y))
a.clear()
a.plot(xList,yList)
a.show()
ani=animation.FuncAnimation(f,animate, interval=1000)
没有用于获取动画计时器的图形画布 通常,您会使用pyplot(
import matplotlib.pyplot as plt
),并让它通过plt.figure()
或plt.subplot()
为您创建一个带有画布的图形
如果您不这样做,您需要手动将图形附加到画布上,此外,您当然需要通过受支持的框架之一,如Tk、PyQt、Wx等
您希望选择哪条路线,这个问题并不清楚,这取决于您创建的应用程序的最终目的