我需要你的帮助,解决我最近处理它的问题。 我可以绘制从我的手机蓝牙传输并通过我的笔记本电脑的COM端口接收的串行数据。乍一看,它似乎是好的,但最多它可以每260毫秒(〜3 fps)绘制。但手机每100毫秒发送一次数据。我很确定这个问题来源于“情节”和“身材”命令,这让我感到困惑。我很感激,如果有人可以纠正我的代码:在Matplotlib中使用动画功能缓慢绘图,Python
from Tkinter import *
import serial
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ser = serial.Serial("COM4", baudrate=115200, timeout=0.1)
cnt=0
xComponent=[]
plt.ylim(0,30)
while (ser.inWaiting() == 0): # Wait here until there is data
pass
def animate(i):
BluetoothString = ser.readline()
ser.flush()
dataArray = BluetoothString.split(',')
x = float(dataArray[2]) # we only need 3rd component
xComponent.append(x)
print xComponent
ax1.clear()
ax1.plot(xComponent)
plt.ylim(0,25)
global cnt
if (cnt > 16):
xComponent.pop(0)
else:
cnt = cnt + 1
ani = animation.FuncAnimation(fig, animate, interval=0)
plt.show()
这段代码什么都不做。 “FuncAnimation”在哪里? – furas
@furas它来自[mpl](http://matplotlib.org/api/animation_api.html#matplotlib.animation.FuncAnimation) – Aaron
我知道'FuncAnimation'是来自'mpl',但我确实在你的代码中看到它。但我看到你改变了代码。 – furas